Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Imagine you also have a Shape subclass Circle, then the following would be legal, too:
LinkedList<? extends Shape> list = new LinkedList<Circle>();
Should the compiler allow you to add Box instances to that List?
Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Michael Remijan:
That's exactly the point. I want to put Shapes in the list whether they be Box, Circle, or Elipse.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
Originally posted by Michael Remijan:
I still do not understand why LinkedList<? extends Shape> does not work because this is suppose to hold a list of "an unknown type that is a subtype of T"
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Rick O'Shay:
Even if Circle was replaced with Box it would not work. Allowing a reference declaration with a bounded wild card is for use in a generic class or method not as means of declaring a reference to use with a instance of that class or method. Again, the test is this: are you writing a generic class or method or using one? If it's the latter than do not use wild cards even if it let's you declare such a reference; that's not the purpose.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
"I'm not back." - Bill Harding, Twister
Not so fast naughty spawn! I want you to know about
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|