Suppress duplicate warnings in IntelliJ IDEA by annotation

Sebastian picture Sebastian · Apr 26, 2016 · Viewed 32k times · Source

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?

Answer

crea1 picture crea1 · Apr 27, 2016

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() {
    ...
}