3 ms·
The Optional<T> in Guava just forces one to explicitly check for null and then get the container object during development. A typical pattern would be: Given
by grdvnl 13y ago
The Optional<T> in Guava just forces one to explicitly check for null and then get the container object during development. A typical pattern would be:
Given an object a of type Optional<MyObject>, we write:
if (a.isPresent()){
MyObject o = a.get()
}
Of course, I could still do a.get() without evaluating isPresent() and end up with an java.lang.IllegalStateException. Here, we are "reminded" to do the null check.
- mercurial 13y agoYou can force Maybe in Haskell, and get a bad surprise at runtime as well.