• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic