Andoridx Room rx问题 [英] Andoridx Room rx issue
本文介绍了Andoridx Room rx问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始使用支持io.reactivex
返回类型的最新androidx.room
版本.
I'm start to use latest androidx.room
version that support io.reactivex
return type.
dependencies {
def room_version = "2.1.0-alpha02"
implementation "androidx.room:room-rxjava2:$room_version"
kapt "androidx.room:room-compiler:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
}
简单的dao类
@Dao
interface UserDao : BaseDao<UserTable> {
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertUser(user: UserTable):Maybe<Long>
@Update
fun updateUser(user:UserTable):Completable
@Query("DELETE FROM $USER_TABLE")
fun clear()
}
生成UserDao_Impl.java
错误
错误:从内部类内部访问本地变量用户;需要声明为最终
error: local variable user is accessed from within inner class; needs to be declared final
突出显示的字段就是这种方法
Highlighted field is in this method
@Override
public Maybe<Long> insertUser(UserTable user) {
return Maybe.fromCallable(new Callable<Long>() {
@Override
public Long call() throws Exception {
__db.beginTransaction();
try {
long _result =
__insertionAdapterOfUserTable.insertAndReturnId(user);//error line
__db.setTransactionSuccessful();
return _result;
} finally {
__db.endTransaction();
}
}
});
}
的确,(UserTable user)
应该在Java中声明为final,但它是生成的类.
有没有人遇到过这个?
It's true that (UserTable user)
should be declared as final in java but it is generated class.
Does any one came across this?
推荐答案
我遇到了同样的问题.通过添加
I had the same problem. Solved it by adding
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
在build.gradle中
in build.gradle
这篇关于Andoridx Room rx问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文