Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics refresher

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when Generics are involved, type conversion is based on the parameterized type (List, LinkedList) or on the parameter to the type (Integer, Number)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic