有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Suppress warning~参数X的实际值始终为Y

我的Android Java代码有一个包含cancel方法的类:

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);
}

但由于(到目前为止)我只使用参数aniDuration = 0调用了此cancel方法一次,因此Android Studio调试器显示以下警告消息:

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

enter image description here

除了使用@SuppressWarnings("all")之外,我如何抑制这种类型的警告


共 (2) 个答案

  1. # 1 楼答案

    您可以使用

    @SuppressWarnings("SameParameterValue")
    
  2. # 2 楼答案

    文件>;设置>;编辑>;检查>;查找:“实际方法参数为同一常数” 取消选中并重新启动android studio