Since I upgrade Java from 1.4.2 to 1.5.002, each time
I got those generics warning messages.
Please help me get rid those messages.
public class MyClass {
private Vector vector;
public MyClass(Vector vector) { this.vector = vector; }
public Vector getVector() { return vector; }
public void addVector(Object object) { vector.addElement(object); }
}
....
MyClass dude = new MyClass(new Vector<String>());
dude.addVector("The Hell");
// Here I got warning from MyClass addVector method
warning: [unchecked] unchecked call to addElement(E) as a member of the
raw type java.util.Vector
vector.addElement(object);
Vector<String> vv = dude.getVector();
// Here I also get warning message
warning: [unchecked] unchecked cast
found : java.util.Vector
required: java.util.Vector<String>
Vector<String> vv = (Vector<String>)dude.getVector();
Can someone out there help me get rid those warning messages?
Thank Q very much in advance!!
Ingo R. Homann - 29 Jun 2005 13:54 GMT
Hi RC,
you are mixing generics and non-generic code. Try the following:
public class MyClass<T> {
private Vector<T> vector;
public MyClass(Vector<T> vector) { this.vector = vector; }
public Vector<T> getVector() { return vector; }
public void addVector(T object) { vector.addElement(object); }
}
Ciao,
Ingo
Tjerk Wolterink - 29 Jun 2005 21:34 GMT
> Since I upgrade Java from 1.4.2 to 1.5.002, each time
> I got those generics warning messages.
[quoted text clipped - 30 lines]
> Can someone out there help me get rid those warning messages?
> Thank Q very much in advance!!
You can just ignore those warning message if you want your app to be compatible
with java 1.4
Dale King - 30 Jun 2005 06:24 GMT
>> Since I upgrade Java from 1.4.2 to 1.5.002, each time
>> I got those generics warning messages.
[quoted text clipped - 34 lines]
> compatible
> with java 1.4
That's not really an issue in this case, since the OP is actually using
generics so he will not be compatible with 1.4. The issue is that he is
mixing generics with non-generics.

Signature
Dale King
Tjerk Wolterink - 30 Jun 2005 16:49 GMT
> That's not really an issue in this case, since the OP is actually using
> generics so he will not be compatible with 1.4. The issue is that he is
> mixing generics with non-generics.
ow my fault.