title: Return class type and have class type as parameter
body: <p>I have function</p>
  
  <pre><code>private Class readObject (ObjectInput in, Class objectclass){
      try {
          Object o = in.readObject ();
  
          if (o instanceof objectclass) {
              return (objectclass)o;
          }
  
      } catch (Exception e) {
  
  } 
  </code></pre>
  
  <p>In my class I am calling this function with:</p>
  
  <pre><code>ObjectInput in = (..)
  Type1 type = readObject (in, Type1.class);
  (do something with type)
  while(true){
      Type2 type2 = readObject (in, Type2.class);
      (do something with type2)
  </code></pre>
  
  <p>Basically, readObject is supposed to return the class that I have as a parameter, if that is the correct type of Object o. You can think of this as, I have Type1, Type2 and Type3 objects that I am reading, but if I come across Type3 I do nothing.</p>
  
  <p>This code that I have written does not work properly. For example,</p>
  
  <pre><code>Type1 type = readObject (in, Type1.class);
  </code></pre>
  
  <p>gives me the warning "cannot convert from Class to Type1".</p>