Optional<Integer> foo; //.... if (foo != null) { foo.and_then(new Consumer () { function accept(Integer foo) { } }); }
To ensure assignment before use make it final.