我有3个课程,分别是Professional,Doctor和Blog,如下所述:
public class Professional {
}
@DatabaseTable(tableName = "doctors", daoClass = DoctorDao.class)
public class Doctor extends Professional {
@DatabaseField(columnName = "id", generatedId = true)
Long id;
@DatabaseField(columnName = "name")
String name;
public Doctor() {
}
}
@DatabaseTable(tableName = "blogs", daoClass = BlogDao.class)
public class Blog<T> {
@DatabaseField(columnName = "id", generatedId = true)
Long id;
@DatabaseField(columnName = "title")
String title;
@DatabaseField(columnName = "blog_of", foreign = true, canBeNull = false, foreignAutoCreate = true)
T author;
}
我无法为Blog类创建DAO,因为我无法通过类Blog调用带有泛型参数的构造函数。 博客的DAO是:
public interface BlogDaoInterface extends Dao<Blog<? extends Professional>, Long> {
}
public class BlogDao extends BaseDaoImpl<Blog<? extends Professional>, Long> implements BlogDaoInterface {
public BlogDao(ConnectionSource connectionSource) throws SQLException {
super(connectionSource, Blog<? extends Professional>.class);
}
}
错误:ormlite无法创建Blog类(即BlogDao)的DAO。代码未成功编译。
我已经使用ormlite通过以下代码行创建表:
TableUtils.createTableIfNotExists(connectionSource, Blog.class);
但是Gradle显示以下错误:
无法从参数化类型中选择
在BlogDao类的构造函数中的以下行:
super(connectionSource, Blog<? extends Professional>.class);
正确的方法是什么?