List<? super String>

Discussion in 'Java' started by Sebastian Bossung, Dec 15, 2004.

  1. 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
     
    Sebastian Bossung, Dec 15, 2004
    #1
    1. Advertising

  2. Sebastian Bossung wrote:
    > 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.
     
    Michael Borgwardt, Dec 15, 2004
    #2
    1. Advertising

  3. Sebastian Bossung

    hilz Guest

    > 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 :)
     
    hilz, Dec 15, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Replies:
    24
    Views:
    10,866
    Darryl Pierce
    Feb 24, 2005
  2. Fernando Rodriguez

    Getting the super class via the super() function

    Fernando Rodriguez, Nov 21, 2003, in forum: Python
    Replies:
    2
    Views:
    749
    Bob Willan
    Nov 22, 2003
  3. Kerim Borchaev

    super. could there be a simpler super?

    Kerim Borchaev, Jan 15, 2004, in forum: Python
    Replies:
    4
    Views:
    492
    Michele Simionato
    Jan 15, 2004
  4. Replies:
    7
    Views:
    450
    Patricia Shanahan
    Apr 6, 2008
  5. GOOD LUCK GROUP
    Replies:
    0
    Views:
    415
    GOOD LUCK GROUP
    Apr 28, 2008
Loading...

Share This Page