Reputation: 132
I'm developing ORM in Java. I want to do this.
class Model {
public static Model find(Object id) {
}
}
class User extends Model;
class Post extends Model;
User user = User.find(15);
Post post = Post.find(1325);
How can I do this, or similar things. I don't want to pass Class object to find method.
Upvotes: 0
Views: 584
Reputation: 308948
You should not do this. A super class can never know how it's extended.
Use generics instead:
package persistence;
public interface GenericDao<T, K extends Serializable>
{
T find(K id);
K save(T value);
void update(T value);
void delete(T value);
}
Upvotes: 2