This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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: 3476

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: 18532
    
  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: 3476

So when Generics are involved, type conversion is based on the parameterized type (List, LinkedList) or on the parameter to the type (Integer, Number)?
 
 
subject: Generics refresher
 
Similar Threads
Generics
Generics
Generics
Generics
Generics