< prev index next >
src/java.base/share/classes/java/lang/Byte.java
Print this page
rev 13019 : 8141678: sun.invoke.util.Wrapper eagerly initializes all integral type caches
Reviewed-by: TBD
@@ -63,10 +63,15 @@
*/
@SuppressWarnings("unchecked")
public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
/**
+ * Zero {@code Byte} constant.
+ */
+ private static final Byte ZERO = new Byte((byte)0);
+
+ /**
* Returns a new {@code String} object representing the
* specified {@code byte}. The radix is assumed to be 10.
*
* @param b the {@code byte} to be converted
* @return the string representation of the specified {@code byte}
@@ -80,12 +85,14 @@
private ByteCache(){}
static final Byte cache[] = new Byte[-(-128) + 127 + 1];
static {
- for(int i = 0; i < cache.length; i++)
- cache[i] = new Byte((byte)(i - 128));
+ for(int i = 0; i < cache.length; i++) {
+ int val = i - 128;
+ cache[i] = (val == 0) ? ZERO : new Byte((byte)val);
+ }
}
}
/**
* Returns a {@code Byte} instance representing the specified
< prev index next >