• Post Reply Bookmark Topic Watch Topic
  • New Topic

Usage of extends and super  RSS feed

 
Richard Hayward
Ranch Hand
Posts: 145
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming Dog -> Animal -> Object,
I understand the difference between & usage of methods such as:

Since I can declare classes like this:

I was expecting to also be able to declare classes like this:

It would mean that if I were to declare a variable t of type T inside Holder, I could assign a Dog or any specialized type of Dog to it.
Is this type of class declaration just illegal?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3926
27
 
Henry Wong
author
Sheriff
Posts: 22678
113
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Hayward wrote:
Is this type of class declaration just illegal?


Assuming that this line was allowed, and assuming that it is similar to extends, and it means that it can be used to hold Dog, Animal, and Object instances ... then ... how is this different from ...



After all, this can also hold Dog, Animal, and Object instances too... so, what would be the purpose?

Henry
 
Richard Hayward
Ranch Hand
Posts: 145
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul & Henry.
Henry Wong wrote:what would be the purpose?

Well, I can't come up with any scenario, apart from something insanely contrived, where this would be useful.
My thinking was that since ? can be followed by either extends or super

then having an identifier T followed by either extends or super would have a pleasing symmetry about it

Nothing to do with being useful!

A good explanation I've found, although I've yet to fully digest it, is here:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!