Using a 'has' method to indicate non-null


IntelliJ is great about telling me when an @Nullable method result isn't checked for null.

However, in some cases I have a method which will provide the same semantics. E.g., 

public class Bar {
* @return true if we have a 'foo'; false otherwise
public boolean hasFoo() {
// code goes here

public Foo getFoo() {
// code goes here

Elsewhere in my code, I may have something like:

if ( bar.hasFoo() ) {

Is there some way to tell IntelliJ that my 'hasFoo' should serve as a null check so that the "bar.getFoo()" is caught by the inspection?





1 comment
Official comment

No, there's no such way currently.

Please sign in to leave a comment.