• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding generics  RSS feed

 
Venu Chakravorty
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't we use the 'super' keyword when defining a generic class or method? Like:


The compiler replies:
A.java:9: > expected
public <Y super Dog> void m2(Y o) {
^
A.java:9: illegal start of type
public <Y super Dog> void m2(Y o) {
^
A.java:9: '(' expected
public <Y super Dog> void m2(Y o) {
^
3 errors

shell returned 1

Regards, Venu.
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
venu chakravorty wrote:Can't we use the 'super' keyword when defining a generic class or method?


This is from Angelika Langer's generics site:

"Type parameters can have several bounds, like in class Box<T extends Number> {...} . But a type parameter can have no lower bound, that is, a construct such as class Box<T super Number> {...} is not permitted. Why not? The answer is: it is pointless because it would not buy you anything, were it allowed. Let us see why it is pointless by exploring what a upper bound on a type parameter means. "
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And here is the source of that statement, including the exploration.
 
Venu Chakravorty
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulrika and Rob.
Sorry for my late reply, my ISP was down.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!