This content has been marked as final. Show 8 replies
In generic, you look at non run time type i.e in your case left side ( type safety during compilation time)
List list=new ArrayList<Integer>(); // here is a List which takes any row type it is sa saying List<? extends Object>
so the compiled type ( the one on the left ) accepts a list of any type which extends Object hence Integer and String all extends Object
Now the second one
List<Integer> list2=new ArrayList(); // you said here I want a list which accept only Integer ( you have to think about the none run time type which is on the left)
There is a type safety now which you have introduced and it is called List<Integer> ; so the compiler will stop you if you try to enter non integer
We have not discussed the wild card which makes things more confusing for you.
Thanks for letting me know that I explained the same idea which you explained before; however, I just quickly browsed the tutorial from http://java.sun.com/docs/books/tutorial/java/generics and I build the conculsion based
"type safety during compilation" and not during run time. to get my thoughts and not more then that.
Deep apology from me.
Alan, it's great that you want to contribute, but you do this all the time: you take an old thread and append some laborious and not necessarily accurate explanation of something that has already been answered. It's just wasting everybody's time.
In this case the question is about a compile error, which happens at compile-time, so of course 'type safety during compilation' is the topic.
If you want to contribute, do make sure you add some value.