• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is List <? super Dog> someList = new ArrayList <Dog>(); allowed even though instance is not a super?  RSS feed

 
Dave McQueen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is List <? super Dog> someList = new ArrayList <Dog>(); allowed even though the instance is not a 'super' of the generic type? I assume it is, since the whole point is to use things polymorphically, but as those annoying company-men types say "When you assume, you make an ASS of 'U' and ME". Brilliant.

Incidentally, I had to put apostrophes around the 'U' since the application assumed I was using the letter instead of the word in the second person. Kind of ruins the moment...
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the List is of type Dog or a super class of Dog. This allows you to insert Dog's into the List.
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave McQueen wrote:Is List <? super Dog> someList = new ArrayList <Dog>(); allowed even though the instance is not a 'super' of the generic type? I assume it is, since the whole point is to use things polymorphically, but as those annoying company-men types say "When you assume, you make an ASS of 'U' and ME". Brilliant.


One of the nice things about programming is that you never have to assume anything. You could have thrown together a simple program that tested your assumptions in less time than it took to write this post and wait for a reply.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With generics, both extends and super include the class itself. extends also is used instead of implements when interfaces are used.
 
Dave McQueen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin Workman wrote:
One of the nice things about programming is that you never have to assume anything. You could have thrown together a simple program that tested your assumptions in less time than it took to write this post and wait for a reply.


Kevin, you're ASSUMING that I have the JDK, JRE and IDE all downloaded or if not, would be able to download them all before I got a reply - which I have to say, was very, very quick.

Incidentally, you're right, I do have them and that was a pretty safe assumption and I realise I could have done that. DOH!
Thanks for your responses folks,

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!