Am 04.02.2009 um 15:57 schrieb John Mazzitelli:
What's the thought on auto-boxing? I saw some checkins related:
- timeout = timeoutProperty.getIntegerValue().intValue();
+ timeout = timeoutProperty.getIntegerValue();
I hate autoboxing. If I see an explicit "intValue()", it tells me
right away this is an Integer and not an int (and I need to
therefore worry about nulls and NPEs).So it helps code-readability
to explicitly not rely on autoboxing, and can avoid coding errors.
I think especially this one would have led to a NPE when the
getIntegerValue() would be NULL, as the
changed code will not.
In general, .intValue() would be ok i guess. If one really checks that
the Integer is indeed not null. I have seen
enough code, where this check just does not happen.
What is bad is new Integer(1) - here autoboxing is more performant, as
is Integer.valueOf(), because of VM-level
caching etc.