aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 18141
    
  39


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)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics refresher
 
Similar Threads
Generics
Generics
Generics
Generics
Generics