title: Select Datatype based on some condition
body: <p>For those who are not using sugarORM in android, what I want is to choose what class datatype should a object have. For example,</p>
  
  <pre><code>Class1 c;
  If(statuscode==1){
      c = new Class1();
  }else if(statuscode==2){
      c = new Class2();
  }else if(statuscode==3){
      c = new Class3();
  }
  </code></pre>
  
  <p>But this will give my cast error in case 2 and case 3. So, how to solve it ?</p>
  
  <p>In detail, for those who know sugarORM in Android</p>
  
  <p>I am using sugarORM in android and I have a situation where I need to select from all rows from any one of the four table based on some condition, or, I need to do something else.</p>
  
  <p>For Example,</p>
  
  <pre><code>List&lt;Table1&gt; list = Table1.listAll(Table1.class);
  or
  Table1 t = new Table1();
  </code></pre>
  
  <p>Now, based on status code of an Intent I am receiving, I need to use Table1, Table2, Table3 or Table4</p>
  
  <p>Means, I need to use either</p>
  
  <pre><code>List&lt;Table1&gt; list = Table1.listAll(Table1.class);
  or
  List&lt;Table2&gt; list = Table2.listAll(Table2.class);
  or
  List&lt;Table3&gt; list = Table3.listAll(Table3.class);
  or
  List&lt;Table4&gt; list = Table4.listAll(Table4.class);
  </code></pre>
  
  <p>How can I do that ?</p>
  
  <p>What I tried is, to use switch case everywhere in my code wherever I need to list all rows or instantiate a new object of that Table</p>
  
  <pre><code>        List&lt;Table1&gt; list=null;
          switch (statuscode){ //statuscode in Integer 1,2,3,4
              case 1:
                  list = Table1.listAll(Table1.class);
                  break;
              case 2:
                  list = Table2.listAll(Table2.class);
                  break;
              case 3:
                  list = Table3.listAll(Table3.class);
                  break;
          }
  </code></pre>
  
  <p>But obviously case 2 and case 3 will give cast error</p>
  
  <p>So, whats the solution for this type of problem ?</p>