This week's book giveaway is in the JDBC forum.
We're giving away four copies of SQL Antipatterns: Avoiding the Pitfalls of Database Programming and have Bill Karwin on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP) and the fly likes ? extends String The Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP)
Reply Bookmark "? extends String" Watch "? extends String" New topic
Author

? extends String

Rodolfo Mendoza
Greenhorn

Joined: Feb 27, 2008
Posts: 14
Hi guys,
Anyone knows why the following code don't work :


The following work fine:


Thanks,
Uttara Rishi
Ranch Hand

Joined: Feb 24, 2008
Posts: 49


You cannot add anything to a List that uses <? extends> or <?>
You can add only when the method signature is <? super Dog?

In short

<? extends> - no adding.
<?> - you can pass anytype into the method but still no adding.
<? super> - adding allowed.

Hope that helps. Please correct me if I am wrong.

Uttara Rishi.
Rodolfo Mendoza
Greenhorn

Joined: Feb 27, 2008
Posts: 14
Uttara thanks
You are right...
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
You cannot add anything to a List that uses <? extends> or <?>

Thats correct but with little exception that you can add 'null'.
Uttara Rishi
Ranch Hand

Joined: Feb 24, 2008
Posts: 49
Thanks Ahmed.
 
 
subject: ? extends String
 
Java Business RIA redefined!