What is the purpose of StatementWithEmptyBody?

  • A+

when I created the drawer bar in Android Studio for my project, in the code for the select items put the next:

@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { 

But what is the use of this annotation?


Warning itself explains meaning.

return type of onNavigationItemSelected is boolean. and we need to return any Boolean value.

If there is if condition in onNavigationItemSelected and not returned then @SuppressWarnings("StatementWithEmptyBody") need to add.


@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) {     int id = item.getItemId();     if (id == R.id.xyz) {        // you should return boolean value here.     }     return false; } 

In example we are returning false by-default. and we haven't return any value in

if (id == R.id.xyz) condition.

You can clearly have a look at warning.

What is the purpose of StatementWithEmptyBody?


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: