Hello Ankit,
my problem with this is that the Java 6 Study Guide says (page 603) that a warning should come from the TestLegacy class as well as the Inserter class.
The reason being:
If I am writing code using generics, and I am calling methods from an external package that I did not implement, that method could be adding Objects to my typed collections that is not of the right type (here
String instead of Integer).
Since that external package is already compiled, I don't get any warning. Worse, I won't know that there is a problem until all hell breaks loose when I execute the code (and I won't even get an exception when this happens, so good luck debugging).
Edit: Oh, I just figured this out, in the example from the book, the Inserter and TestLegacy class are declared in the same file... But nevertheless, I do see a potential problem here. Why don't we get a warning when calling a method that uses non-generic Collections?
[ December 04, 2008: Message edited by: jean-gobert de coster ]
[ December 04, 2008: Message edited by: jean-gobert de coster ]
[ December 04, 2008: Message edited by: jean-gobert de coster ]