java从数据库生成对象列表

时间:2015-03-28 19:21:56

标签: java class inheritance

我有两个班级:

public abstract class Entry {
    private static String LIST_QUERY     = "SELECT * FROM \"%s\"";
    .
    .
    .
    protected static <T extends Entity> List<T> all(Class<T> cls) {
/*Here I want to load whole database. For each row create own object. For example Article(class is below)*/
   }
}

class Article extends Entry {
   .
   .
   .
    public static List<Article> all() throws SQLException {
        return Entry.all(Article.class);
   }
}

问题是Entry.all()方法内部如何创建Article对象或从Entry继承的任何对象? 我的变种是错误的:

cls<T> instance_of_entity = new cls<T>();//wrong
cls instance_of_entity = new cls();//wrong

0 个答案:

没有答案