title: Multiple super classes and code reuse
body: <p>This question is related to Android in that my need exists in that domain but the question still applies to Java as a whole; I will be using some Android terms here such as <code>Activity</code>, <code>FragmentActivity</code>, <code>ListActivity</code>, etc...</p>
  
  <p>I need to implement an abstract base class that contains functionality which must be used throughout the whole application, more specifically every <code>Activity</code> must use this functionality but I want it to be handled automatically by the base class. My problem is that I have many different types of Activities within the application like <code>Activity</code>, <code>FragmentActivity</code> and <code>ListActivity</code>, all of which extend <code>Activity</code> (minus <code>Activity</code> of course).</p>
  
  <p>Since the code in the base class would be exactly the same for each implementation of <code>Activity</code>, is there a way to avoid code duplication and needing to create a base class for each type of <code>Activity</code>?</p>
  
  <p>What I'm trying to avoid:</p>
  
  <pre class="lang-java prettyprint-override"><code>public abstract class BaseActivity extends Activity
  {
      public void onCreate(Bundle savedBundle)
      {
          // code goes here, will be the exact same for all these base classes
      }
  }
  
  public abstract class BaseFragmentActivity extends FragmentActivity
  {
      public void onCreate(Bundle savedBundle)
      {
          // code goes here, will be the exact same for all these base classes
      }
  }
  
  public abstract class BaseListActivity extends ListActivity
  {
      public void onCreate(Bundle savedBundle)
      {
          // code goes here, will be the exact same for all these base classes
      }
  }
  
  public class MyMainActivity extends BaseActivity
  {
  }
  
  public class MyUserList extends BaseListActivity
  {
  }
  
  public class SomeActivityThatNeedsToBeAFragment extends BaseFragmentActivity
  {
  }
  </code></pre>
  
  <p>I was trying to utilize generics for this by using something like the following</p>
  
  <pre class="lang-java prettyprint-override"><code>public abstract class BaseActivity&lt;T extends Activity&gt; extends T
  </code></pre>
  
  <p>but obviously that won't work; or maybe I'm just doing it wrong. So is there any way to accomplish this code reuse and avoid duplication or am I just simply stuck duplicating my code?</p>
  
  <p>Thanks!</p>