Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
None
-
None
-
None
-
None
Description
- java.lang.Long,
- java.lang.Integer,
- java.lang.Short
- java.lang.Character,
- java.lang.Byte,
- java.lang.Boolean,
- java.math.BigInteger, and
- java.math.BigDecimal
have valueOf(<simple type>) methods. The Java Platform API Specification states that
"If a new [...] instance is not required, this method should generally be used in preference to the constructor [...], as this method is likely to yield significantly better space and time performance by caching frequently requested values.".
If this is true, Groovy should also use cache instances instead of creating new objects. As long as JDK 1.4 is supported this should be done in Groovy's own cache implementations analog to org.codehaus.groovy.runtime.typehandling.IntegerCache.
Attachments
Issue Links
- depends upon
-
GROOVY-1915 Should use Integer.valueOf() instead of new Integer(), where appropriate
- Closed