I am currently studying generics as part of my programming class, and I'm having problems understanding why the following code throws a compiler error:
List<Object> objs = Arrays.asList(1,"2");
From what I'm aware, if you do not explicitly declare the type parameter for the method, for example Arrays.<Integer>asList(); then it is generated for you, using the most reasonable choice.
The following code:
List<Object> objs = Arrays.<Object>asList(1,"2");
works because i'm explicitly telling the compiler, "I want this method's type parameter to be Object", but I am curious why this is not done successfully automatically?
<? extends Object> List<? extends Object> java.util.Arrays.asList(? extends Object... arg0)