|
|
|
|
|
by wtetzner
3429 days ago
|
|
> Again, why is Optional.empty() better then null? Because with Optional the type tells the caller that it might not return a value. With null, you have no idea if you need to check for null or not. Being able to chain maps, filters, etc. is convenient as well, but I'd argue that's just a side benefit. Oh, one other thing Optional can do that null can't: nest. For example, if you call get() on a Map, and it returns null, you can't tell if the key wasn't in the map, or if it's value was null. If get() returned an Optional, then for a Map<String,Optional<String>>, get() would return Optional<Optional<String>>. |
|