java - Why does the JVM allow to set the "high" value for the IntegerCache, but not the "low"? -


we know java has cache integer (and other types) number in range [-128, 127] considered "commonly used".

the cache designed follow :

private static class integercache {     static final int low = -128;     static final int high;     static final integer cache[];      static {         // high value may configured property         int h = 127;         string integercachehighpropvalue =             sun.misc.vm.getsavedproperty("java.lang.integer.integercache.high");         if (integercachehighpropvalue != null) {             try {                 int = parseint(integercachehighpropvalue);                 = math.max(i, 127);                 // maximum array size integer.max_value                 h = math.min(i, integer.max_value - (-low) -1);             } catch( numberformatexception nfe) {                 // if property cannot parsed int, ignore it.             }         }         high = h;          cache = new integer[(high - low) + 1];         int j = low;         for(int k = 0; k < cache.length; k++)             cache[k] = new integer(j++);          // range [-128, 127] must interned (jls7 5.1.7)         assert integercache.high >= 127;     }      private integercache() {} } 

i know can extend high value giving parameter jvm :

java -djava.lang.integer.integercache.high=xxxx aclass.class 

what don't understand why aren't allowed override low value ?

note not trying find workaround, instead understand why not allowed obscure reasons.

found out there unresolved rfp on this.

joe darcy commented on issue :

it conceivable helpful cache greater range of negative number well, of yet there has been no pressing need so.

note rfp offer poor workaround if ever interested in using before handled :

no workaround possible increasing size of cache apart implementing own cache , reffering first before going java.lang.integer class. this not requires calls other classes rather default use of integer.valueof(int i) call.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -