title: Java DAO factory dynamic returned object type
body: <p>I'm trying to write simple DAO that will create entity objects based on their type stored in String field. How to return type that is changed dynamicly?
  Method findById() of UserDAO class should return User class object. Same method for ProductDAO should return Product.
  I don't want to implement findById in every class that extends DAO, it should be done automatically.</p>
  
  <p>Example code:</p>
  
  <pre><code>class DAO {
     protected String entityClass = "";
     public (???) findById(int id) {
        // some DB query
        return (???)EntityFromDatabase; // how to do this?
     }
  }
  class UserDAO extends DAO {
     protected String entityClass = "User";
  }
  class ProductDAO extends DAO {
     protected String entityClass = "Product";
  }
  class User extends Entity {
     public int id;
     public String name;
  }
  </code></pre>