title: Using Generics with Realm + RxJava
body: <p>I'm trying to isolate my layers when building out an application that is going to be maintained for several years. I'm using Realm as a database, Retrofit as a networking layer, and RxJava/RxAndroid as the communication layer in the MVP/MVVM architecture. In the future, I want whoever takes up this project to be able to simply swap out Realm or swap out Retrofit, say if a better library comes out that lends itself to future improvements.</p>
  
  <p>So, to that end, I'm trying to build a generic database interface, and then build my concrete Realm implementation on top of it.</p>
  
  <p>I have a IDatabaseManager interface defined as follows:</p>
  
  <pre><code>public interface IDatabaseManager&lt;E extends AbstractList&lt;? extends T&gt;, T&gt; {
      void save(T object);
      Observable&lt;E&gt; getAsObservable(Class&lt;?&gt; type);
  }
  </code></pre>
  
  <p>The idea being, I want the database manager to have type E which is some list/collection of some class '?' which extends some base object (for those ORMs which require you to extends some base class).</p>
  
  <p>Then, I have my concrete implementation, which utilizes realm:</p>
  
  <pre><code>public class RealmManager implements IDatabaseManager&lt;RealmResults&lt;? extends RealmObject&gt;, RealmObject&gt; {
  
    @Override
    void save(RealmObject object) {
      //implementation works
    }
  
    @Override
    Observable&lt;RealmResults&lt;? extends RealmObject&gt;&gt; getAsObservable(Class&lt;?&gt; type) {
      Realm realm = realm.getDefaultInstance();
      return realm.where(type).findAllAsync().asObservable();
    }
  }
  </code></pre>
  
  <p>However, I'm getting an error on "type" that:</p>
  
  <pre><code>where (java.lang.Class&lt;E&gt;) in Realm cannot be applied
  to    (java.lang.Class&lt;capture&lt;?&gt;&gt;) 
  
  reason: inference variable E has incompatible bounds:
  equality constraints: capture of ?
  upper bounds: Realm Model
  </code></pre>
  
  <p>Realm performs queries by taking in a class of the object collection you're querying, where that object must extend RealmObject (abstract), or implement RealmModel (interface), but they are supposed to be interchangeable.</p>
  
  <p>Any help here? I think I'm just messing up some syntax here and I just can't figure out how I can fix it =/</p>