5 ms·
Not sure of readability, but this surely is a neat trick to avoid null pointer exceptions, etc. (and it can be extended to cover other, related cases..): S
by wfn 13y ago
Not sure of readability, but this surely is a neat trick to avoid null pointer exceptions, etc. (and it can be extended to cover other, related cases..):
String myString = null;
if ("foobar".equals(myString)) { /* ... */ }
- hibikir 13y agoI'd argue that the solution to the problem is to make sure null can't happen, ever. It's way too much boilerplate in Java, but par for the course in, say, Scala. If it can really be null, and it makes sense for it to happen, wrap it in an Option.