When using Optional<T>
with a nullable field, is it more idiomatic to have the setter take
- an
Optional<T>
or - just a
T
and then have it as follows?
public class Bar {
private Optional<T> foo;
public void setFoo(T foo) {
this.foo = Optional.<T>fromNullable(foo);
}
public Optional<T> getFoo() {
return foo;
}
}
.getFoo()
to return? – fge Oct 31 '14 at 19:05.getFoo()
is returning anOptional<T>
– Saulo Silva Oct 31 '14 at 20:46