Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

wildcard generics

Thread view: 
rmacnak@gmail.com - 25 Oct 2006 21:07 GMT
What is the difference between List<Whatever> and List<? extends
Whatever>?
Oliver Wong - 25 Oct 2006 21:28 GMT
> What is the difference between List<Whatever> and List<? extends
> Whatever>?

   You can add an instance of Whatever to a List<Whatever>, but you can't
to a List<? extends Whatever>.

   - Oliver
grasp06110@yahoo.com - 25 Oct 2006 22:17 GMT
Sounds like it would be useful if Whatever is an abstract class or
interface.  If you used ArrayList<Whatever> in this case and added an
instanace of Whatever to the list and then tried to execute an abstract
method you would get a runtime error.  By using ArrayList<? extends
Whatever> if you tried to do this you would get a compile time error.
Cool.
Oliver Wong - 25 Oct 2006 22:45 GMT
> Sounds like it would be useful if Whatever is an abstract class or
> interface.  If you used ArrayList<Whatever> in this case and added an
> instanace of Whatever to the list and then tried to execute an abstract
> method you would get a runtime error.  By using ArrayList<? extends
> Whatever> if you tried to do this you would get a compile time error.
> Cool.

   Note that you can't actually create an instance of an abstract class or
interface; you can only create an instance of one of its subclasses. So
whenever you invoke an abstract method, it would always resolve to some
real, concrete method.

   - Oliver
Bart - 26 Oct 2006 12:14 GMT
> What is the difference between List<Whatever> and List<? extends
> Whatever>?

AFAIK, ListIterator<Whatever> is not compatible with
ListIterator<SomethingThatExtendsWhatever>.

Regards,
Bart.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.