我开始使用支持io.reactivex返回类型的最新androidx.room版本.
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
突出显示的字段在此方法中
@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用户)应该在java中声明为final,但它是生成的类.
有没有人碰到过这个?
解决方法:
我有同样的问题.通过添加解决它
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
在build.gradle中