Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why can�t I add an Integer to a List<? extends Number> ?

800357May 15 2005 — edited May 30 2005
Could someone please explain to me why the following doesn�t work:
List<? extends Number> list = new ArrayList<Integer>();

list.add( new Integer(1) );
This doesn�t compile:
cannot find symbol
symbol  : method add(java.lang.Integer)
location: interface java.util.List<capture of ? extends java.lang.Number>
                list.add( new Integer(1) );
The compiler doesn�t complain when I instantiate the List, only when I try to add something to it. Why does this happen?

Thanks for the help.

Cheers
Matthijs
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2005
Added on May 15 2005
10 comments
1,593 views