SuppressWarnings(未选中)在Intellij中偶尔工作

时间:2018-10-26 11:36:27

标签: java intellij-idea

我一直在研究旧版代码并尝试对其进行清理,显然,您会不时收到警告,除了抑制警告之外,您无能为力。

不幸的是,由于某种原因,并不是SuppressWarnings(“ unchecked”)的所有注释都起作用,并且当我运行构建时,一些方法抛出了应该抑制的抱怨。

例如,

NewExerciseChildFragment editExercise = new NewExerciseChildFragment();
Bundle bundle = new Bundle();
bundle.putInt("groupPosition", groupPosition);
bundle.putString("exerciseName", exerciseName);
bundle.putDouble("weight", weight);
bundle.putInt("reps", reps);
bundle.putInt("sets", sets);

editExercise.setArguments(bundle);
editExercise.show(getFragmentManager(), "showEditedExercise"); 

在编译

时发出警告
public class Foo extends Bar {

public Foo () {
    // Some code
}

@Override
@SuppressWarnings("unchecked")
public Object visit(Visitor v) { 
    v.accept(this);
}
//Other code omitted. 
}

奇怪的是,当IntelliJ对文件实时运行分析时,它不会报告任何错误或警告,这只会在编译期间弹出。 另外,如果我在类级别使用抑制,则可以删除警告,但是我不想使用该解决方案,因为它不适用于大型类。

有人能够解释发生了什么事,以及如何最好地解决这个问题?

0 个答案:

没有答案
相关问题