Why does this one does not work:
ArrayList<LinkedList<int>>
where this one does:
ArrayList<LinkedList<Integer>>
???
Because Java can only use classes (and not primitive types) and arrays (also arrays for primitives) for generics (between < and >).
List<Integer> list;
That is also a reason why there are wrapper classes for primitive types:
int -> Integer
boolean -> Boolean
double -> Double
byte -> Byte
etc...
The argument in the <> must be an object because those classes can only hold objects.
int is a primitive type, where as Integer is simply a wrapper class for that type, so Integer is the one that will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With