< prev index next >

src/java.base/share/classes/java/lang/Long.java

Print this page
rev 13019 : 8141678: sun.invoke.util.Wrapper eagerly initializes all integral type caches
Reviewed-by: TBD

@@ -74,10 +74,15 @@
      */
     @SuppressWarnings("unchecked")
     public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
 
     /**
+     * Zero {@code Long} constant.
+     */
+    private static final Long ZERO = new Long(0L);
+
+    /**
      * Returns a string representation of the first argument in the
      * radix specified by the second argument.
      *
      * <p>If the radix is smaller than {@code Character.MIN_RADIX}
      * or larger than {@code Character.MAX_RADIX}, then the radix

@@ -1050,12 +1055,14 @@
         private LongCache(){}
 
         static final Long cache[] = new Long[-(-128) + 127 + 1];
 
         static {
-            for(int i = 0; i < cache.length; i++)
-                cache[i] = new Long(i - 128);
+            for(int i = 0; i < cache.length; i++) {
+                int val = i - 128;
+                cache[i] = (val == 0) ? ZERO : new Long(val);
+            }
         }
     }
 
     /**
      * Returns a {@code Long} instance representing the specified
< prev index next >