title: RxJava 2.0 conversion to generic loses all types
body: <p>I've inherited some code I need to generalize, which uses RxJava 2.0 for some stuff - namely requesting the data from a REST service (using Retrofit) and then parsing that using our own custom parser.</p>
  
  <p>We have two slightly different implementations of the same flow, and I've been trying to unify them, without much luck - as soon as I start using the generic parent types, <code>subscribe()</code> loses every type and returns Objects instead.</p>
  
  <p>The code is the following (simplified a bit to match NDA):</p>
  
  <pre><code>// MyStuff is a base class, which has two child classes inheriting
  // Base processing is done in the abstract class, while type-specific
  // processing is done in ParserOne and ParserTwo
  public abstract class ParserBase&lt;T extends MyStuff&gt; {
      // This call will be specific to the actual MyStuffOne or MyStuffTwo objects, hence abstract
      public abstract Flowable&lt;TargetModel&gt; parse(Flowable&lt;T&gt; parsestuff);
      // These two calls are applied to the generic MyStuff class
      // and are shared between MyStuffOne and MyStuffTwo 
      public Flowable&lt;Map&lt;long,MyModel&gt;&gt; parseOneImpl(Flowable&lt;T&gt; parsestuff) { /* impl here */ }
      public Single&lt;Map&lt;long,MyModel&gt;&gt; parseTwoImpl(Flowable&lt;T&gt; parsestuff) { /* impl here */ }
  }
  
  public class MyStuff {
      // Some common fields here
  }
  
  public class MyStuffOne extends MyStuff {
      // Some MyStuffOne specific fields here
  }
  
  public class MyStuffTwo extends MyStuff {
      // Some MyStuffTwo specific fields here
  }
  
  public class ParserOne extends ParserBase&lt;MyStuffOne&gt; {
      @Override 
      public Flowable&lt;TargetModel&gt; parse(Flowable&lt;MyStuffOne&gt; parsestuff) { /* impl 1 here */ }
  }
  
  public class ParserTwo extends ParserBase&lt;MyStuffTwo&gt; {
      @Override 
      public Flowable&lt;TargetModel&gt; parse(Flowable&lt;MyStuffTwo&gt; parsestuff) { /* impl 2 here */ }
  }
  
  public class MyClassOne {
  
      protected void call() {
          ParserOne parser = new ParserOne();
          callGeneric(parser);
      }
  
      protected void callGeneric(ParserBase&lt;?&gt; parser) {
          // Common implementation here
          parser.parseOneImpl(whatever).subscribe(
              result -&gt; { /* result ends up being Object instead of Map&lt;Long,MyModel&gt; */ }, 
              throwable -&gt; { /* throwable also ends up being Object */ });
      }
  }
  
  public class MyClassTwo extends MyClassOne {
      @Override
      protected void call() {
          ParserTwo parser = new ParserTwo();
          callGeneric(parser);
      }
  }
  </code></pre>
  
  <p>So while the <code>parseOneImpl()</code> call has a generic parameter, it has a fixed return type - but for some reason, <code>subscribe()</code> does not see this and instead returns generic Objects. I could work around this by casting the result (which works fine, since the actual runtime object matches the return type of <code>parseOneImpl()</code>), but I'd like to avoid that.</p>
  
  <p>What am I doing wrong here?</p>