Next privilege 125 Rep.
Next badge 0/1
0 people reached
- 0 posts edited
- 0 helpful flags
- 47 votes cast
null values vs “empty” singleton for optional fields
Using Option core methods isEmpty()/isDefined() and get() works perfectly fine from Java.
How to implement isValid correctly?
You can use an intermediate Builder object, responsible of the construction of the final object and of tracking the errors alongside. Then you can have a build() method that throws if Builder#isValid() doesn't pass and SomeObject is always created correctly.