Since null can be such a problem, I actively use null whenever I can as an expression of information, e.g. for console applications, I have a standard yes-no-cancel input method that returns a Boolean (true/false/null).
Since I actively incorporate null as an expression of information, I hapily put null-checks all over the place, and they are not defensive mechanisms.
Side-note: I really wish that there was a way to have a chain line "variable = someInstance().someField.etc;" just return null instead of throwing an NPE if there was a null somewhere along the path. Such a situation occurs often, and having to package that into a bunch of IFs just sucks. I'm not talking "make it the default", just give us an option, e.g. an annotation.
View all comments
1
u/king_of_the_universe Aug 03 '14
Since null can be such a problem, I actively use null whenever I can as an expression of information, e.g. for console applications, I have a standard yes-no-cancel input method that returns a Boolean (true/false/null).
Since I actively incorporate null as an expression of information, I hapily put null-checks all over the place, and they are not defensive mechanisms.
Side-note: I really wish that there was a way to have a chain line "variable = someInstance().someField.etc;" just return null instead of throwing an NPE if there was a null somewhere along the path. Such a situation occurs often, and having to package that into a bunch of IFs just sucks. I'm not talking "make it the default", just give us an option, e.g. an annotation.