title: Subclass With Changed Type in Java
body: <p>Is it possible in Java to create a subclass and do a sort of find and replace for a type? To change an instance variable to be a <code>Integer</code> instead of a <code>Double</code>?</p>
  
  <p>I am looking for a vector class that holds integers. I mean a real math vector, not a <code>java.util.Vector</code>.</p>
  
  <p>In <code>org.apache.commons.math3</code> there are <a href="http://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/geometry/euclidean/twod/Vector2D.html" rel="nofollow"><code>Vector2D</code></a> and <a href="http://commons.apache.org/proper/commons-math/javadocs/api-3.3/index.html" rel="nofollow"><code>ArrayRealVector</code></a> classes, but they both only take <code>Double</code> for their coordinates.</p>
  
  <p>I would love to be able to somehow subclass them to use <code>Integer</code>s instead. I know I could subclass the abstract class they extend from, but that seems like a whole ton of code deduplication, judging by how long their implementations are (<a href="http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Vector2D.java?view=markup" rel="nofollow">source of Vector2d</a> and <a href="http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/ArrayRealVector.java?view=markup" rel="nofollow">source of ArrayRealVector</a>).</p>
  
  <p>I know I could also typecast my <code>Integer</code>s to <code>Double</code>s when constructing and getting values back, but again this seems a little messy.</p>