Extending List<Float>

Discussion in 'Java' started by Aleksi Kallio, Jul 13, 2005.

  1. This is something many people seem to have problems with, but didn't
    find any solutions that actually work. Generics are quite complicated on
    these issues...

    I'm trying to make my own float list that implements List<Float>
    (java.util.List, using generics).


    I'm getting a warning:

    Type safety: The return type Float of the method get(int) of type
    FloatArrayList needs unchecked conversion to conform to the return type
    E of inherited method

    Relevant code is:

    public class FloatArrayList implements List<Float> {

    // ...

    public Float get(int index) {
    return new Float(data[index]);
    }

    // ...
    }

    It's just a warning, so everything works perfectly. But anyway I would
    like to keep my Eclipse problems-window clean. :)
     
    Aleksi Kallio, Jul 13, 2005
    #1
    1. Advertising

  2. Hi,

    Aleksi Kallio wrote:
    > I'm getting a warning:
    >
    > Type safety: The return type Float of the method get(int) of type
    > FloatArrayList needs unchecked conversion to conform to the return type
    > E of inherited method
    >
    > Relevant code is:
    >
    > public class FloatArrayList implements List<Float> {
    >
    > // ...
    >
    > public Float get(int index) {
    > return new Float(data[index]);
    > }
    >
    > // ...
    > }


    Compiling the source you provided (and adding the missing methods) I do
    *not* get a warning!

    Ciao,
    Ingo
     
    Ingo R. Homann, Jul 13, 2005
    #2
    1. Advertising

  3. Aleksi Kallio

    Roland Guest

    On 13-7-2005 12:37, Aleksi Kallio wrote:
    > This is something many people seem to have problems with, but didn't
    > find any solutions that actually work. Generics are quite complicated on
    > these issues...
    >
    > I'm trying to make my own float list that implements List<Float>
    > (java.util.List, using generics).
    >
    >
    > I'm getting a warning:
    >
    > Type safety: The return type Float of the method get(int) of type
    > FloatArrayList needs unchecked conversion to conform to the return type
    > E of inherited method
    >
    > Relevant code is:
    >
    > public class FloatArrayList implements List<Float> {
    >
    > // ...
    >
    > public Float get(int index) {
    > return new Float(data[index]);
    > }
    >
    > // ...
    > }
    >
    > It's just a warning, so everything works perfectly. But anyway I would
    > like to keep my Eclipse problems-window clean. :)


    Same result as Ingo: I don't get a warning (I'm using Eclipse 3.1).

    Which version of Eclipse are you using? Early Milestones of 3.1 (3.1M*)
    did have some bugs in this area (flagging some generic
    expressions/operations with a warning or even an error while there
    shouldn't be one).

    Have you tried closing and reopening the file. Or even closing and
    restarting Eclipse. I've noticed that Eclipse 3.1 sometimes hangs on to
    an error/warning even when the file has changed and saved. Reopening /
    restarting often cures it. On another occasion, a project rebuild
    cleared the error (menu Project -> Clean).
    --
    Regards,

    Roland de Ruiter
    ` ___ ___
    `/__/ w_/ /__/
    / \ /_/ / \
     
    Roland, Jul 13, 2005
    #3
  4. Aleksi Kallio

    Joan Guest

    "Aleksi Kallio" <> wrote in message
    news:42d4eecb$0$1690$...
    > This is something many people seem to have problems with, but didn't
    > find any solutions that actually work. Generics are quite complicated on
    > these issues...
    >
    > I'm trying to make my own float list that implements List<Float>
    > (java.util.List, using generics).
    >
    >
    > I'm getting a warning:
    >
    > Type safety: The return type Float of the method get(int) of type
    > FloatArrayList needs unchecked conversion to conform to the return type
    > E of inherited method
    >
    > Relevant code is:
    >
    > public class FloatArrayList implements List<Float> {
    >
    > // ...


    I am just starting to use generics so my question is why have a class and
    not this:

    static List<Float> sArray = new ArrayList<Float>(32);
     
    Joan, Jul 13, 2005
    #4
  5. > I am just starting to use generics so my question is why have a class and
    > not this:
    > static List<Float> sArray = new ArrayList<Float>(32);


    I'm building my own implementation which is backed with a float array.
    It combines efficiency of a plain array and elegancy of a List-container.
     
    Aleksi Kallio, Jul 14, 2005
    #5
  6. Aleksi Kallio

    Joan Guest

    "Aleksi Kallio" <> wrote in message
    news:42d60628$0$1688$...
    > > I am just starting to use generics so my question is why have a class

    and
    > > not this:
    > > static List<Float> sArray = new ArrayList<Float>(32);

    >
    > I'm building my own implementation which is backed with a float array.
    > It combines efficiency of a plain array and elegancy of a List-container.


    My book says that ArrayList uses an array internally.
     
    Joan, Jul 15, 2005
    #6
  7. Thomas Weidenfeller, Jul 15, 2005
    #7
    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. Andy
    Replies:
    7
    Views:
    6,329
    Roedy Green
    May 10, 2004
  2. Jim West
    Replies:
    4
    Views:
    1,514
    Jeff Schwab
    Jan 16, 2004
  3. bd
    Replies:
    0
    Views:
    665
  4. Carsten Fuchs
    Replies:
    45
    Views:
    1,651
    James Kanze
    Oct 8, 2009
  5. Jp Hastings-spital

    Extending Float

    Jp Hastings-spital, May 21, 2009, in forum: Ruby
    Replies:
    5
    Views:
    176
    Robert Dober
    May 22, 2009
Loading...

Share This Page