I found a bug in my code which is similar to this gist: https://gist.github.com/rompetroll/667bf46ac0168a92497a
If I define a lambda like this directly in a .thenApply(Func)
method, I will get the unreported exception compile error.
Does not work:
Optional o = Optional.of(nullable);
return myComplFuture
.thenApply(o -> o.orElseThrow(() -> new RuntimeException("nah"));
This does work:
Optional o = Optional.of(nullable);
Function<Optional<String>, String> stringOrException = o -> o.orElseThrow(() -> new RuntimeException("nah");
return myComplFuture
.thenApply(stringOrException);
So, please can anyone tell me, why the first does not compile but the latter does? Can also please anyone tell me how to mark this error in eclipse?
Things I tried:
Window -> Preferences -> Java -> Compiler -> Errors/Warnings
But I didn't find anything which would show me the compiler error in eclipse. In fact, eclipse does not show a red x next to this line. But everytime I run mvn test
the compiler complains as shown in the gist.
Thanks in advance!