This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
shiva shankar wrote:Why cant I use just Shape directly
Perhaps I am missing a better example.
Wel this code can only accept List<Shape> . It means that you can not use subclass of Shape while calling this method. It can only be List of Shape nothing else.
For this reason generics are diffrent from arrays. To enable this method to receive any subclass of Shape you have to use syntax List<? extends Shape> shape. But there is one constraint here to use this syntax, you can not modify the list in the method. you can only read the list content. If you try to modify then it will give an exception.