title: Java generics - accept float and int
body: <p>How can I program my class to accept both Integers and Floats, I suppose I'll need to use generics, am I correct?</p>
  
  <pre><code>public class Vec2 {
  
  private int x, y;
  
  public Vec2(int xa, int ya) {
      this.x = xa;
      this.y = ya;
  }
  public Vec2() {
      this(0, 0);
  }
  public Vec2(Vec2 vec) {
      this(vec.x, vec.y);
  }
  
  public void addX(int xa) {
      x+=xa; // I get an exception here when I try to use generics.
  }
  public void addY(int ya) {
      y+=ya; // I get an exception here when I try to use generics.
  }
  </code></pre>
  
  <p>Any ideas how to program my class to accept floats, integers and doubles altogether?</p>