uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marshall Schor <...@schor.com>
Subject New Java 1.5 construct to use
Date Tue, 04 Dec 2007 21:27:09 GMT
In many places in our code we "box" ints using new Integer(anInt).

Java 5, I discovered via some "findbugs" runs, now has a new static
method in the Integer class, with a signature of

This is equivalent to the new Integer(...) construct, except that the
JVM caches these values, and reuses an existing value, thus
(potentially) reducing both space and time.

Unless the code needs unique Integers (for instance, if it is using
these for wait/notify locks), consider changing these (after our 2.1.1
gets out of course :-) ).

Also true for other primitive types like short, long, byte, boolean
etc.  Boolean is interesting - there are only 2 values to cache :-)

Another thing to consider changing for Java 5 is StringBuffer  into
StringBuilder, if no synchronization is needed (which is usually the case).

Cheers. -Marshall

View raw message