Original Post
Hello, I don't know if this is possible but I have this class to hold an X and Y value for a vector in two-dimensional space. I want it to be generic so I can have it be an Integer vector, or Double, or whatever kind of Number. Here is my class and my question. Is there anyway to have a no-arg constructor in this and have it set default variables? I have tried adding "this(0,0);" to call the other constructor but having that defeats generics. I don't want to always have to pass something in when I create a new vector. It's not like this is a big problem, it will only save me a couple keys strokes each time. Thanks for any suggestions.
public class Vector2D<T>{
private T x;
private T y;
public Vector2D(){
//Add something here to set default X and Y
}
public Vector2D(T x, T y){
setX(x);
setY(y);
}
public T getX(){
return this.x;
}
public T getY(){
return this.y;
}
public void setX(T x){
this.x = x;
}
public void setY(T y){
this.y = y;
}
}