src/share/classes/java/lang/Integer.java

Print this page




 621             }
 622             high = h;
 623 
 624             cache = new Integer[(high - low) + 1];
 625             int j = low;
 626             for(int k = 0; k < cache.length; k++)
 627                 cache[k] = new Integer(j++);
 628         }
 629 
 630         private IntegerCache() {}
 631     }
 632 
 633     /**
 634      * Returns an {@code Integer} instance representing the specified
 635      * {@code int} value.  If a new {@code Integer} instance is not
 636      * required, this method should generally be used in preference to
 637      * the constructor {@link #Integer(int)}, as this method is likely
 638      * to yield significantly better space and time performance by
 639      * caching frequently requested values.
 640      *



 641      * @param  i an {@code int} value.
 642      * @return an {@code Integer} instance representing {@code i}.
 643      * @since  1.5
 644      */
 645     public static Integer valueOf(int i) {
 646         assert IntegerCache.high >= 127;
 647         if (i >= IntegerCache.low && i <= IntegerCache.high)
 648             return IntegerCache.cache[i + (-IntegerCache.low)];
 649         return new Integer(i);
 650     }
 651 
 652     /**
 653      * The value of the {@code Integer}.
 654      *
 655      * @serial
 656      */
 657     private final int value;
 658 
 659     /**
 660      * Constructs a newly allocated {@code Integer} object that




 621             }
 622             high = h;
 623 
 624             cache = new Integer[(high - low) + 1];
 625             int j = low;
 626             for(int k = 0; k < cache.length; k++)
 627                 cache[k] = new Integer(j++);
 628         }
 629 
 630         private IntegerCache() {}
 631     }
 632 
 633     /**
 634      * Returns an {@code Integer} instance representing the specified
 635      * {@code int} value.  If a new {@code Integer} instance is not
 636      * required, this method should generally be used in preference to
 637      * the constructor {@link #Integer(int)}, as this method is likely
 638      * to yield significantly better space and time performance by
 639      * caching frequently requested values.
 640      *
 641      * This method will always cache values in the range -128 to 127,
 642      * inclusive, and may cache other values outside of this range.
 643      *
 644      * @param  i an {@code int} value.
 645      * @return an {@code Integer} instance representing {@code i}.
 646      * @since  1.5
 647      */
 648     public static Integer valueOf(int i) {
 649         assert IntegerCache.high >= 127;
 650         if (i >= IntegerCache.low && i <= IntegerCache.high)
 651             return IntegerCache.cache[i + (-IntegerCache.low)];
 652         return new Integer(i);
 653     }
 654 
 655     /**
 656      * The value of the {@code Integer}.
 657      *
 658      * @serial
 659      */
 660     private final int value;
 661 
 662     /**
 663      * Constructs a newly allocated {@code Integer} object that