Conclusion 1 :


In java , Parent class or interface reference can hold child class object , this is called polymorphism . But coming to generics polymorphism will be applicable for base type but not for parameter type. See the below samples

List<String> l = new ArrayList<String>(); ( ✅ )
Collection<String> l = new ArrayList<String>(); ( ✅ )
List<Object> l = new ArrayList<String>(); ( ✖ ) // causes compiler error



Conclusion 2 :


While defining collection in generic manner , the parameter type should be object type . primitive types are not allowed . See below samples.

List<String> l = new ArrayList<String>(); ( ✅ )
List <int> l = new ArrayList<int>(); ( ✖ ) // causes compiler error