Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generic class declaration

 
Serg Masow
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

can anyone tell me why

class Test<T extends Number> {}

is perfectly legal, but

class Test<T super Number> {}

not?
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Serg,

Welcome to Javaranch. Basically, the issue here is that Java does not allow lower bounds for type parameters, i.e. "<T super Foo>" is always invalid syntax. It does allow lower bounds for wildcards, e.g. "<? super Foo>".

You may want to check out this other thread from last week where we briefly discussed this same issue.
 
Serg Masow
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kelvin,

many thanks for your answer and the link.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic