This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
1] This method should be called with a parameter of type List<String>, but it can be called with a parameter of type List 2]The disadvantage is that the compiler won�t catch errors . instead, errors will cause a ClassCastException 3] This is necessary for backward compatibility Similarly, the Iterator need not be an Iterator<String>
But I am cofuse with first point . why it allow to call this method with any list ( I mean , a list which is not paramaterized by String ( can have other than String ) )
Originally posted by rathi ji: ... But I am cofuse with first point . why it allow to call this method with any list ( I mean, a list which is not paramaterized by String ( can have other than String ) )...
The parameterized type is List<String>. To allow for backward compatability, a non-typed List will also be accepted (compiling with a warning, but no error). However, a List with a type parameter other than String will not compile. [ March 01, 2005: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Oct 11, 2004
Means this is acceptable :
List myList = new ArrayList(); printListOfStrings(myList); // just show warnings
but this will give compile time error :
List<Integer> myList = new ArrayList<Integer>(); printListOfStrings(myList); // compile time error