This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Generics refresher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generics refresher" Watch "Generics refresher" New topic
Author

Generics refresher

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Hi,
In Java Generics, type conversion is based on the base type, not the parameters to that type.
Why this code is failing?

Conversion is based on List and LinkedList, not on Integer and Number.
Thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18753
    
  40


Think about what would happen if the compiler allowed the assignment.

If the assignment was allowed....





Then didn't I just put a double object into the ints list?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

So when Generics are involved, type conversion is based on the parameterized type (List, LinkedList) or on the parameter to the type (Integer, Number)?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Generics refresher