title: How can one create an abstract, immutable class?
body: <p>Here's the short version. First and foremost: I want my class to be immutable. I know that a class can't be both abstract and final. <strong>What I'm asking is: is there a way to <em>only</em> allow inner classes to extend and implement the outer, abstract class?</strong> This may not be the best method to achieve my immutable goals, so if somebody has a better design, I would love to hear it.</p>
  
  <p>I am writing a class for vector operations -- as in physics and engineering, not the programming sense. (I'm also aware that <a href="http://jscience.org/api/org/jscience/mathematics/vector/package-summary.html" rel="noreferrer">JScience has a package</a> for this kind of stuff. I want to write my own, and keep it simple.)</p>
  
  <p>I like the pattern used in Java's geometry package, wherein, say, a <code>Line2D</code> can be created using one of two precision levels: float or double.</p>
  
  <pre><code>public abstract class Line2D {
      public static class Float extends Line2D { /* Implementation */ }
      public static class Double extends Line2D { /* Implementation */ }
  }
  </code></pre>
  
  <p>This is a feature I would really like to incorporate and expand upon in my class, so I created the following:</p>
  
  <pre><code>public abstract class Vector2D {
  
      public final static class Integer extends Vector2D {
  
          // Component length projected along x/y axis, respectively
          final private int i, j;
  
          public Integer( int i, int j ) {
              this.i = i;
              this.j = j;
          }
  
          public Object doStuff() { /* vector operations */ }
      }
  
      public final static class Float extends Vector2D {
          // Identical to Vector2D.Integer, except with floats
      }
  
      public final static class Double extends Vector2D { /* Same Idea */ }
  
      // Outer class methods and whatnot
  }
  </code></pre>
  
  <p>Obviously, <code>Vector2D.Integer</code>, <code>Vector2D.Float</code>, and <code>Vector2D.Double</code> are all final. Is there any way to make <code>Vector2D</code> final to everything except these inner classes?</p>