Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SuppressWarnings for: Boolean method 'methodName' is always inverted

The list of the most common SuppressWarnings annotations is so long and non-intuitive, that I am lost to find a correct annotation for warning

Boolean method 'methodName' is always inverted

I don't want to change the method to return a negative value, since there is a logic consistency in the naming - e.g. method name is: hasFlag(...).

What is the right annotation for this type of Lint Analysis warning?

like image 203
Ωmega Avatar asked Oct 04 '18 13:10

Ωmega


People also ask

What is invert method in Java?

The Invert Boolean refactoring lets you change the sense of a Boolean method or variable to the opposite one.

How does SuppressWarnings work?

@SuppressWarnings instruct the compiler to ignore or suppress, specified compiler warning in annotated element and all program elements inside that element. For example, if a class is annotated to suppress a particular warning, then a warning generated in a method inside that class will also be separated.

What is the use of @SuppressWarnings deprecation?

The @SuppressWarnings annotation disables certain compiler warnings. In this case, the warning about deprecated code ( "deprecation" ) and unused local variables or unused private methods ( "unused" ).

What is the use of @SuppressWarnings unchecked?

@SuppressWarnings("unchecked") is used when Java generics just don't let you do what you want to, and thus, you need to explicitly specify to the compiler that whatever you are doing is legal and can be executed at the time of execution.


1 Answers

@SuppressWarnings("BooleanMethodIsAlwaysInverted")

You can discover these with the help of Android Studio. Expand the quick fix menu (alt+enter on my computer) and then choose one of the suppress quick fixes.

like image 99
laalto Avatar answered Oct 26 '22 17:10

laalto