Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning ~ Actual value of parameter X is always Y

Tags:

java

android

My Android Java code has a class that includes cancel method:

private void hide(int aniDuration) {     if (!isVisible) return;     if (runnable != null) handler.removeCallbacks(runnable);     isVisible = false;     if (aniDuration > 0) {         fadeInOut(false, aniDuration);     }     else {         notifierLayout.setAlpha(0.0f);         notifierLayout.setVisibility(View.GONE);     } }  private void hide() { hide(animateDuration); }  @SuppressWarnings({"unused", "WeakerAccess"}) public void cancel() { hide(); }  @SuppressWarnings({"unused", "WeakerAccess"}) public void cancel(int aniDuration) {     hide(aniDuration); } 

But since (so far) I call this cancel method just once with the parameter aniDuration = 0, the Android Studio debugger shows the following warning message:

Actual value of parameter "aniDuration" is always "0"

enter image description here

Besides of using @SuppressWarnings("all"), how could I suppress this type of warning?

like image 435
Ωmega Avatar asked Feb 11 '18 18:02

Ωmega


People also ask

What is suppress warning?

Annotation Type SuppressWarningsIndicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element). Note that the set of warnings suppressed in a given element is a superset of the warnings suppressed in all containing elements.

What is the use of suppress warning in Java?

Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code. 1. @SuppressWarnings("unchecked") public class Calculator { } - Here, it will ignore all unchecked warnings coming from that class.


1 Answers

You can suppress it with

JAVA:

@SuppressWarnings("SameParameterValue")   

KOTLIN:

@Suppress("SameParameterValue") 
like image 194
laalto Avatar answered Oct 03 '22 06:10

laalto