任何人都可以帮我将这段代码转换成lambda表达式, 我很震惊这个
Observable.create(new OnSubscribe<User>() {
@Override
public void call(Subscriber<? super User> arg0) {
User updatedUser = userService.updateuser(usermapper.userdtotoentity(user));
arg0.onNext(updatedUser);
}
}).subscribe(new Action1<User>() {
@Override
public void call(User user) {
if (user != null) {
response.resume(user);
} else
response.resume(Response.status(Status.NOT_FOUND).build());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t) {
logger.debug("User with email_id:" + email_id + " is not present");
response.resume(t);
}
});
答案 0 :(得分:3)
Observable.<User>create(subscriber -> {
User updatedUser = userService.updateuser(usermapper.userdtotoentity(user));
subscriber.onNext(updatedUser);
}).subscribe(
user -> {
if (user != null) {
response.resume(user);
} else {
response.resume(Response.status(Status.NOT_FOUND).build());
}
},
error -> {
logger.debug("User with email_id:" + email_id + " is not present");
response.resume(error);
}
);