2 ms·
So, you can do the following: interface OverOptional<S,T> extends Consumer<T> { public S getResult(); }; Which allows you to create an anonymo
by dllthomas 12y ago
So, you can do the following:
interface OverOptional<S,T> extends Consumer<T> {
public S getResult();
};
Which allows you to create an anonymous class that embodies the first two arguments of maybe:
Optional<Integer> maybe_int = Optional.of(7);
OverOptional<Boolean, Integer> is_seven_or_empty
= new OverOptional<Boolean, Integer>() {
private Boolean result = true; // default
public void accept(Integer i) {
result = i == 7;
}
public Boolean getResult() { return result; }
};
maybe_int.ifPresent(is_seven_or_empty);
return is_seven_or_empty.getResult();