我正在使用 Room 架构组件来实现持久性。我创建了通用的 DAO 接口(interface)以避免样板代码。 Room Pro Tips
但是我的代码没有编译说“错误:(21、19)错误:参数的类型必须是用@Entity 注释的类或其集合/数组。”对于通用类 T。
interface BaseDao<T> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(T... entity);
@Update
void update(T entity);
@Delete
void delete(T entity);
}
@Dao
public abstract class ReasonDao implements BaseDao<ReasonDao> {
@Query("SELECT * from Reason")
abstract public List<Reason> getReasons();
}
这里有什么我遗漏的吗? 它是这样工作的 here
最佳答案
在 gradle 中从这里更改:
kapt "androidx.room:room-compiler:$roomVersion"
为此:
annotationProcessor "androidx.room:room-compiler:$room_version"
关于java - "Type of the parameter must be a class annotated with @Entity"在 Room 中创建 Generic DAO 接口(interface)时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48015280/