US
class A{}
class B extends A{
public B(){}
}
public class Main {
public static void main(String[] args) {
// write your code here
B b = new B();
Optional<B> someB = Optional.of(b);
Optional<A> someA = someB;
}
}
Size: a a a
US
ZM
IO
AD
AD
IO
IO
AD
AD
AD
IO
NG
IO
IO
MO
Function<Integer, Optional<Integer>> f = x -> {
if (x == null) {
x = -1;
} else if (x == 2) {
x = null;
} else {
x = x + 1;
}
return Optional.ofNullable(x);
};
Optional.of(1).flatMap(f).equals(f.apply(1)); // ok
Optional.ofNullable((Integer) null).flatMap(f).equals(f.apply(null)); // упс
SP
IO
AD
SP
IO