Android Room不接受通用字段类型 [英] Android Room's does not accept generic field type
问题描述
我正在尝试创建一个基类,其id字段具有通用类型,例如
I'm trying to have a base class which id field is of a generic type like
class BaseEntity<T>{
private T id;
//get, set;
}
class User extends BaseEntity<String> {
//blah blah blah
}
我有一个这样的DAO:
and I have a DAO like this:
@Dao
public interface UserDao {
@Query("SELECT * FROM user WHERE id = :id")
Flowable<User> getUserById(String id);
}
我得到一个编译错误:
app \ build \ generated \ source \ apt \ irrisimples \ debug \ com \ irrisimples \ data \ source \ local \ UserDao_Impl.java:275:错误:找不到符号 最后的T _tmpId; ^
app\build\generated\source\apt\irrisimples\debug\com\irrisimples\data\source\local\UserDao_Impl.java:275: error: cannot find symbol final T _tmpId; ^
并在UserDao_Impl:275中:
and in UserDao_Impl:275:
最终T _tmpId; _tmpId = _cursor.getString(_cursorIndexOfId);
final T _tmpId; _tmpId = _cursor.getString(_cursorIndexOfId);
因此,这意味着Room无法确定T是什么,而无法替换其中的值.是错误还是我做错了什么?
So this means that Room couldn't figure out what was T and replace the value there. Is it a bug or am I doing something wrong?
P.S:使用Android Studio 3.1 BETA 3和Room 1.0.0(经测试1.1.0-alpha2)
P.S: Using Android Studio 3.1 BETA 3, and Room 1.0.0 (tested 1.1.0-alpha2)
推荐答案
参考 Google问题跟踪器
应在1.1.0-alpha3中修复
It should be fixed in 1.1.0-alpha3
这篇关于Android Room不接受通用字段类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!