Re: A problem regarding generics
Vikram wrote:
Where as the following does not give any compile time error
List list = new ArrayList<String>();
Really? No error? What about the "unchecked" warning, then?
Hm?
Because I get errors (well, ok, warnings, but a warning is a flavor of error)
about the use of a "raw type conversion" if I try that construct.
If no generics is specified, isin't it implied that it contains
object? What is the reason the second statement does not give any
compile time error?
"Foo extends Bar" does not mean "List <Foo> extends List <Bar>". This is
explained in detail in every generics tutorial and reference.
Which of course you've read.
They then go on to explain that generics wildcards ("?" notation) resolve
this, sort of.
<http://java.sun.com/docs/books/tutorial/java/generics/subtyping.html>
& ff.
Eric Sosman wrote:
The on-line Java Tutorial has a section on generics that you
might find helpful:
<http://java.sun.com/docs/books/tutorial/java/generics/index.html>
Since you've read this tutorial thoroughly and it hasn't answered all our
question, now read the free chapter (ch. 5) on generics from Joshua Bloch's
/Effective Java/, available as a PDF download from
<http://java.sun.com/docs/books/effective/java>
<http://www.google.com/search?q=Java+generics+introduction>
is another good resource. AMong other sources, that will steer you to
<http://www.angelikalanger.com/Articles/JavaPro/01.JavaGenericsIntroduction/JavaGenerics.html>
--
Lew