title: Java abstract class to get type of extended class
body: <p>I don't how to phrase this, so I'll drop an example</p>
  
  <pre><code>class AbstractUser&lt;A extends AbstractAccount&lt;? extends AbstractType&gt;&gt; {
      // I want a method that has access to Type
      // And returns the specific Type that extends AbstractType
      protected &lt;T extends AbstractType&gt; T doSomething(T type) {
          // do stuff
          // and return the type specific type T
      }
  }
  
  class AbstractAccount&lt;T extends AbstractType&gt; {
  
  }
  
  class AbstractType {
  
  }
  
  
  class Type extends AbstractType {
  
  }
  
  class Account extends AbstractAccount&lt;Type&gt; {
  
  }
  
  class AccountAdmin extends AbstractAccount&lt;Type&gt; {
  
  }
  
  class User extends AbstractUser&lt;Account&gt; {
  
  }
  </code></pre>
  
  <p>What I want in this is that within <code>User</code> class I can do <code>getType()</code> and it returns the the specific type of <code>AbstractAccount</code>, in this case <code>Account</code>. </p>
  
  <p>How do I do this without specifying any more templates? In other words, I want whatever type the <code>?</code> in <code>? extends AbstractType</code> is to be in that method</p>
  
  <p>So if I do</p>
  
  <pre><code>final Account account = ...
  final AccountAdmin admin = ...
  final User user = ...
  user.doSomething(account); // should work
  user.doSomething(AccountAdmin); // should fail
  </code></pre>