Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

I'd like to use

java.util.Optional.orElseThrow()

with an Exception type that asks for a constructor parameter. Something like this:

orElseThrow(MyException::new(someArgument)) // obviously NOT working

Is there a way to create a Supplier that passes my argument value in?

1 Answer

0 votes
by (46k points)

 Yeah, 

. orElseThrow(() -> new MyException(someArgument)).

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...