I'm not really sure what is wrong with my code...
public Vector blob (Pixel px)
{
Vector v = new Vector();
Point p = new Point(px.getX(), px.getY());
v.add(p);
return v;
}
I get the following: warning: [unchecked] unchecked call to add(E) as a member of the raw type Vector
v.add(p);
where E is a type-variable: E extends Object declared in class Vector.
Looking through the API, the add function takes an object as a param which I clearly make the line before, ideas?
Starting with Java-5, java.util.Vector<E>
is a generic container, meaning (in very plain terms) that you can specify the type of the element that you are planing to store, and have the compiler check that type for you automatically. Using it without the type of the element is OK, but it triggers a warning.
This should get rid of the warning, and provide additional type safety checks:
public Vector<Point> blob (Pixel px) {
Vector<Point> v = new Vector<Point>();
Point p = new Point(px.getX(), px.getY());
v.add(p);
}
Another thing to note about vectors is that they are synchronized containers. If you are not planning to use the fact that they are synchronized, you may be better off with ArrayList<E>
containers.
Generics!!!. You have to specify the Object type for the contents of the vector. To remove the warning the vector code should be like this
Vector<Point> v=new Vector<Point>()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With