rom*_*eso 3 android java-8 retrofit dagger-2
我已经按照谷歌直接编写的本教程.
我目前遇到的问题是班级userDao.save(response.body());内部的问题UserRepository.
private void refreshUser(final String userId) {
executor.execute(() -> {
// running in a background thread
// check if user was fetched recently
boolean userExists = userDao.hasUser(FRESH_TIMEOUT);
if (!userExists) {
// refresh the data
Response response = webservice.getUser(userId).execute();
// TODO check for error etc.
// Update the database.The LiveData will automatically refresh so
// we don't need to do anything else here besides updating the database
userDao.save(response.body());
}
});
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在我的Android Studio版本中执行此操作时,我收到一条消息,指出此语言级别不支持Lambda表达式.
我知道的事实,我可以升级我的Android Studio来支持Java 8像那个,但是-有一种其他的方式来做到这一点?我不想仅仅为了使用Lambda Expressions而升级到Java 8.
如果您不想使用Java 8(您应该重新考虑),可以手动替换:
executor.execute(() -> {
// task...
});
Run Code Online (Sandbox Code Playgroud)
有:
executor.execute(new Runnable() {
@Override
public void run() {
// task...
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
925 次 |
| 最近记录: |