GeeCON Prague 2014*
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


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: 18876
    
  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)?
 
GeeCON Prague 2014
 
subject: Generics refresher