1

What is the best way convert following traditional java validation into java 8 functional programming way?

if (obj != null) {
    if(obj.isValid) {
     someService.update(obj);
  }
}

obj is an Optional instance. Eg:

Optional<Car> obj = Optional.ofNullable(dao.getCar())
0

1 Answer 1

5
obj.filter(e -> e.isValid).ifPresent(someService::update)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.