Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress duplicate warnings in IntelliJ IDEA by annotation

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?

like image 864
Sebastian Avatar asked Apr 26 '16 13:04

Sebastian


People also ask

What is duplicated code fragment?

Code Inspection: Duplicated code fragmentReports duplicated blocks of code from the selected scope: the same file or the entire project. The inspection features quick-fixes that help you to set the size of detected duplicates, navigate to repetitive code fragments, and compare them in a tool window.


2 Answers

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() {     ... } 
like image 100
crea1 Avatar answered Sep 29 '22 03:09

crea1


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)

like image 37
user6658417 Avatar answered Sep 29 '22 02:09

user6658417