4 ms·
I never get why people have trouble with NPE. If you stick to two rules, you're out of misery - never store null in a field, a collection, etc - checks al
by _old_dude_ 5y ago
I never get why people have trouble with NPE.
If you stick to two rules, you're out of misery
- never store null in a field, a collection, etc
- checks all parameters that are not nullable (most of them) with Objects.requireNonNull
(it's what Kotlin does automatically BTW)
- kevinmgranger 5y agoThis boils down to "just don't make mistakes."
- _old_dude_ 5y agoYou still have PEBKAC but it's easy to find because a null can not cross the method boundary, so no snowball effect.
- nindalf 5y ago"There are no bad languages, only bad programmers"
- imtringued 5y ago>checks all parameters that are not nullable (most of them) with Objects.requireNonNull I would go as far as say 95% of them are. So now your code is filled with effectively pointless checks (you run into an error at runtime instead of compile time) if your language had non nullable variables in the first place.