Android studio marks warnings in Java code, some of them I consider useless and want to disable them. I know I can configure Inspections that are enabled, but for some of these I can't find where it can be disabled. Then code is marked to have issues, and I want to have clean code so that I see real problems. Example of warning:
'if' statement can be replaced with 'return ...'
And I don't want to put annotations to my code, rather I'd like to switch this off in IDE. Thanks
When you click on the lightbulb and then on the suggested action's arrow, you get submenu with options. First one should be "Edit inspection profile setting", which should navigate you to the exact place in Settings, where you can edit given inspection.
This is a more general answer for future viewers. These are various ways to suppress the warning.
Add the following comment above the line with the if
statement.
//noinspection SimplifiableIfStatement
if (...)
Add the following line at the beginning of the method.
@SuppressWarnings("SimplifiableIfStatement")
private boolean myIfMethod() {
if (...) return false;
return (...);
}
Add the following line at the beginning of the class.
@SuppressWarnings("SimplifiableIfStatement")
public class MyClass { ... }
Position your cursor on the if
statement and press Alt + Enter. Then choose Simplify > Disable inspection.
Position your cursor on the if
statement and press Alt + Enter. Then choose
If you disabled the inspection by mistake, you can turn it on again.
if
statement. (However, sometimes I find the "simplification" harder to read. Thus my answer here.)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With