List<? super String>

S

Sebastian Bossung

Hi all,

I have a problem understanding generics, specifically the use of "super". I
have this code:

protected void methodA(List<? super String> list) {
list.add(new String());
}

Which I think should be legal, because list is declared to be a list of
String or supertype so I should be able to add String instances to it.
Thinks me. But the compiler says that this is an
"Unsafe wildcard operation: The method add(? super String) of type List<?
super String> is not applicable for the arguments (String)".

I am using Eclipse (3.0.0 with JDT Preview plugin and JDK 1.5.0 on Linux).

Thanks for any help!

Sebastian
 
M

Michael Borgwardt

Sebastian said:
Hi all,

I have a problem understanding generics, specifically the use of "super". I
have this code:

protected void methodA(List<? super String> list) {
list.add(new String());
}

Which I think should be legal,

I agree, as does Sun's Java tutorial.

I am using Eclipse (3.0.0 with JDT Preview plugin and JDK 1.5.0 on Linux).

I'm not sure what the "JDT Preview plugin" is, but even the latest eclipse beta
release 3.1M2 does not handle generics very well and sometimes shows problems that
disappear when you "clean" the Project or even persist even though the code
compiles fine with javac.
 
H

hilz

I'm not sure what the "JDT Preview plugin" is, but even the latest eclipse
beta
release 3.1M2 does not handle generics very well and sometimes shows problems that
disappear when you "clean" the Project or even persist even though the code
compiles fine with javac.

That's why you need to try NetBeans 4.0 (just released)!

Me ducks :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top