I was going through wildcard topic in Java where i got stuck at this code below
static <T> void type(List<? super T> list){
//...
}
static <T> void type2(List<? extends T> list){
//...
}
If you call these methods by this code, it gives an error and that's understandable
List<?> unbounded=new ArrayList<Long>();
//! type(unbounded); //:Error here
//! type2(unbounded); //:Same Error here
But if you change signature of these methods by adding one extra arg, like this
static <T> void type(List<? super T> list, T arg){
//...
}
static <T> void type2(List<? extends T> list, T arg){
//...
}
and call them by
List<?> unbounded=new ArrayList<Long>();
Long lng=90L;
//! type(unbounded,lng); //:Error here
type2(unbounded,lng); //No error in this one now
Why this behavior just by adding one extra arg?? How come bounded list accept unbounded one just by addition of one xtra arg??