Since Java 5, we\'ve had boxing/unboxing of primitive types so that int
is wrapped to be java.lang.Integer
, and so and and so forth.
I see
Besides performance and memory issues, I'd like to come up with another issue: The List interface would be broken without int
.
The problem is the overloaded remove()
method (remove(int) vs. remove(Object)). remove(Integer)
would always resolve to calling the latter, so you could not remove an element by index.
On the other hand, there is a pitfall when trying to add and remove an int
:
final int i = 42;
final List list = new ArrayList();
list.add(i); // add(Object)
list.remove(i); // remove(int) - Ouch!