In my example below I want to avoid writing getView != null every time I want to use getView. To keep it cleaner I create a method hasView() which does the check for me. However I still get a warning. Is there any way around this?
import android.support.annotation.Nullable;
public void showView(){
if(hasView()){
getView().show(); // Shows warning Method invocation 'showLoading' may produce 'java.lang.NullPointerException'
}
}
boolean hasView(){
return getView() != null;
}
@Nullable
private View getView(){
return view;
}
I am using Android Studio/IntelliJ. I know that I can use @SuppressWarnings I have seen this question but this makes the code uglier.