Suppress duplicate warnings in IntelliJ IDEA by annotation

谁都会走 提交于 2019-12-03 02:55:29

问题


Since version 15, IntelliJ warns me about code duplicates.

In some cases this might be intentional, so I want to ignore/suppress this warning by using the @SuppressWarnings annotation. But what is the correct value for this?

Edit: I'm not asking for disabling this kind of inspection completely as in question Is it possible to disable duplicate code detection in Intellij?


回答1:


This works for me. You have to set it on both classes/methods if you want to suppress the warning both places.

@SuppressWarnings("Duplicates")
private void myDuplicatedMethod() {
    ...
}



回答2:


Just saw this and thought I would throw this in for posterity. To suppress for just one block rather than the whole method, you can use a line comment:

//noinspection Duplicates

(I also find it handy to do this for unchecked) (I'm using version 2016-2, but I think this has been around awhile)




回答3:


Thank you for all the answers. There is also another more generic approach to suppress warnings:

  1. Place the cursor within the code that gives you a warning
  2. Hit Alt+Enter
  3. Go to the warning entry (in this case "Navigate to duplicate")
  4. Don't hit Enter but (right arrow)
  5. Now you can select some suppressing options (for class/method/statement)



来源:https://stackoverflow.com/questions/36865842/suppress-duplicate-warnings-in-intellij-idea-by-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!