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.
when we compile the code. Compiler doesn't let you do the compile sucessfully because of this code
what happens exactly is , when we call poll method ,At compile time, compiler only checks the reference variable "l" type i.e., "List" contains poll method or not. if List contains that method then only compiler let you compile the code sucessfully....
I hope you understood...........
[ December 14, 2008: Message edited by: ShaikSalam Bashoeb ]
[ December 14, 2008: Message edited by: ShaikSalam Bashoeb ] [ December 14, 2008: Message edited by: ShaikSalam Bashoeb ]
ShaikSalem is correct, but maybe a little more detail would be welcome.
Go through the Java Tutorials, and look particularly at the List and Queue interfaces. If you look at the API you find that LinkedList is a kind of List, and it is also a kind of Queue (look at the top where it says about interfaces). If you say List<String> lll = new LinkedList<String>(); the compiler interprets that as:
If you click on the names of the interfaces (or find the full descriptions of the methods) in the API link, you can work out which interfaces the methods come from. If you said "List" then you are going to use the LinkedList as a List; if you said Queue then it would mean you are going to use the LinkedList as a Queue. In both instances you get the methods of those interfaces, and the other methods are not visible to the compiler.
If you had said Queue<String> qqq = new LinkedList<String>(); the compiler would have only found the methods which are in the Queue interface; you could then change the LinkedList to an ArrayDeque and it would still work.
Joined: Feb 22, 2007
Dear ShaikSalam Bashoeb, Campbell Ritchie
Thank you so much for your beautiful explanations. I really appreciate it.