title: Inherit from any subclass of a superclass (Java)
body: <p>I'm namely a C++ programmer, and in C++ I could do something like this:</p>
  
  <pre><code>class SuperSuper
  {
      virtual void newItem()=0;
  }
  
  class SubSuperA:public SuperSuper
  {
       virtual void newItem()
       {
           //do something
       }
  }
  
  class SubSuperB:public SuperSuper
  {
       virtual void newItem()
       {
           //do something different (disappear! :)
       }
  }
  
  template &lt;class T&gt;
  class SubSub:public T
  {
      virtual void newItem()
      {
           T::newItem();
           //do a third thing
      }
  }
  </code></pre>
  
  <p>I want to do this in Java, however I'm getting the feeling that it (at least directly) isn't possible</p>
  
  <p>I set up the first three classes easily in Java as follows:</p>
  
  <pre><code>public abstract class SuperSuper
  {
      abstract void newItem(Item item);
  }
  
  public class SubSuperA extends SuperSuper
  {
      @Override void newItem(Item item)
      {
          //stuff
      }
  }
  
  public class SubSuperB extends SuperSuper
  {
      @Override void newItem(Item item)
      {
          //other stuff
      }
  }
  //SubSuperC,D,etc
  </code></pre>
  
  <p>And currently am implementing the fourth like so:</p>
  
  <pre><code>SubSuperA sa=new SubSuperA() {
      @Override public void newItem(Item item)
      {
          super.newItem(item);
          //A lot of stuff that will be changing constantly throughout development
      }
  };
  
  SubSuperB sb=new SubSuperB() {
      @Override public void newItem(Item item)
      {
          super.newItem(item);
          //A lot of stuff that will be changing constantly throughout development
      }
  };
  </code></pre>
  
  <p>Please note that both of the overrides are of the same function.  No matter what SubSuper* it is based on, the replacement newItem() is identical.  Obviously this would be a nightmare to maintain.  I was hoping I could just declare a SubSub class like this </p>
  
  <pre><code> public class SubSub&lt;T&gt; extends T {
      @Override public void newItem(Item item)
      {
          super.newItem(item);
          //A lot of stuff that will be changing constantly throughout development
      }
   }
  </code></pre>
  
  <p>that I could just instantiate like this</p>
  
  <pre><code> SubSub ss=new SubSub&lt;SubSuperA&gt;
  </code></pre>
  
  <p>etc...  but this errors in java:</p>
  
  <pre><code>"Cannot refer to the type parameter T as a supertype."
  </code></pre>
  
  <p>I looked around based on that error and found <a href="https://stackoverflow.com/questions/2000478/extend-from-generic-supertype">Extend from Generic Supertype?</a> which claims that what I want to do isn't possible using that method.</p>
  
  <p>What I actually need to do: I have a platform agnostic twitter client that just handles receiving tweets, storing them etc.  It has an abstract Column class (SuperSuper) that I can extend for various different types of columns (SubSuper) (home timeline, mentions, etc) and each filters out what tweets they want to display in newItem().  I want to be able to plug various GUIs into it for different platforms, and I need the client to call a GUI specific function (SubSub) to handle adding each individual tweet to the GUI library.  Having a GUI specific class that can extend any Column derived class would be the ideal solution</p>
  
  <p>Since apparently this direct implementation isn't possible in Java, I am wondering if there is some syntactic trickery that will achieve something fairly similar, or if I should just go off creating an interface that will be stored and called by SuperSuper and SuperSub* and implemented by my GUI handler instead of SubSub. </p>