Extending List<Float>

A

Aleksi Kallio

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. :)
 
I

Ingo R. Homann

Hi,

Aleksi said:
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
 
R

Roland

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_/ /__/
/ \ /_/ / \
 
J

Joan

Aleksi Kallio said:
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);
 
A

Aleksi Kallio

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.
 
J

Joan

Aleksi Kallio said:
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.
 
T

Thomas Weidenfeller

Joan said:
My book says that ArrayList uses an array internally.

An array of Objects, not one of the particular primitive type. So for
every float you store in an ArrayList you get a corresponding
java.lang.Float wrapper object. Which is not too great.

/Thomas
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top