Why does the JVM allow to set the “high” value for the IntegerCache, but not the “low”?

前端 未结 1 772
轮回少年
轮回少年 2021-01-17 08:04

We all know that Java has a cache for Integer (and some other types) for number in the range [-128, 127] which are considered to be \"commonly used

1条回答
  •  感情败类
    2021-01-17 08:43

    Found out that there is already an unresolved RFP on this.

    Joe Darcy commented on the issue :

    It is conceivable that it would be helpful to cache a greater range of negative number as well, but as of yet there has been no pressing need to do so.

    Note that the RFP offer a poor workaround if ever someone was interested in using this before it is handled :

    No workaround possible for increasing the size of the cache apart from Implementing your own cache and reffering to this first before going to the java.lang.Integer class. This is obviously not good as it requires calls to other classes rather than just the default use of the Integer.valueOf(int i) call.

    0 讨论(0)
提交回复
热议问题