Java does not allow primitive types to be used in generic data structures. E.g. ArrayList<int> is not allowed. The reason is, primitive types can not be directly converted to Object. However Java 1.5 does support auto-boxing, and wrapper classes work in generic data structures. So why couldn’t the compiler auto-box it to ArrayList<Integer>? Are there any other reasons for why this can not work?
Share
So as far as I understand it, your proposed
ArrayList<int>would be identical toArrayList<Integer>. Is that right? (In other words, internally it still stores an Integer; and every time you put something in or get it out, it would automatically box/unbox it, but autoboxing/autounboxing already does that forArrayList<Integer>.)If it is the same, then I don’t understand what the utility of having a duplicate syntax
<int>is when it means the same thing as<Integer>. (In fact it will introduce additional problems, because for exampleint[]is not the same runtime type asInteger[], so if you haveT[], andTisint, what would it mean?)