diff options
Diffstat (limited to 'libjava/classpath/java/lang/Byte.java')
-rw-r--r-- | libjava/classpath/java/lang/Byte.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/libjava/classpath/java/lang/Byte.java b/libjava/classpath/java/lang/Byte.java index 7f53a494b95..a1536e1be1b 100644 --- a/libjava/classpath/java/lang/Byte.java +++ b/libjava/classpath/java/lang/Byte.java @@ -88,6 +88,11 @@ public final class Byte extends Number implements Comparable<Byte> // This caches Byte values, and is used by boxing conversions via // valueOf(). We're required to cache all possible values here. private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1]; + static + { + for (int i=MIN_VALUE; i <= MAX_VALUE; i++) + byteCache[i - MIN_VALUE] = new Byte((byte) i); + } /** @@ -185,7 +190,7 @@ public final class Byte extends Number implements Comparable<Byte> */ public static Byte valueOf(String s, int radix) { - return new Byte(parseByte(s, radix)); + return valueOf(parseByte(s, radix)); } /** @@ -201,7 +206,7 @@ public final class Byte extends Number implements Comparable<Byte> */ public static Byte valueOf(String s) { - return new Byte(parseByte(s, 10)); + return valueOf(parseByte(s, 10)); } /** @@ -214,12 +219,7 @@ public final class Byte extends Number implements Comparable<Byte> */ public static Byte valueOf(byte val) { - synchronized (byteCache) - { - if (byteCache[val - MIN_VALUE] == null) - byteCache[val - MIN_VALUE] = new Byte(val); - return byteCache[val - MIN_VALUE]; - } + return byteCache[val - MIN_VALUE]; } /** @@ -258,7 +258,7 @@ public final class Byte extends Number implements Comparable<Byte> int i = Integer.parseInt(s, 10, true); if ((byte) i != i) throw new NumberFormatException(); - return new Byte((byte) i); + return valueOf((byte) i); } /** |