9

When IDEA has the following code:

final public static String unused="";

It will show "unused" in grey with a squiggle underscore and a tooltip that say "Field 'unused' is never used".

However this code:

enum MyEnum{
  UNUSED
}

does not show the squiggle. I can run Analyze|Inspect Code to get an "Unused declaration" message in the "Inspection Results".

Is there a way to make IDEA find the unused fields of an enum automatically when opening the code in the editor?

User1
  • 39,458
  • 69
  • 187
  • 265

2 Answers2

1

As said in here go to Settings|search for unused declaration and under Java click on that. On the right, there are all available things you can do with it.

Sam
  • 1,832
  • 19
  • 35
  • 5
    There are checkboxes for Classes, Inner classes, Fields, Methods, Parameters, and Local variables. They are all checked. There is not a checkbox for Enums, yet. v2017.1.3 – User1 Jun 14 '17 at 20:08
  • you could submit a feature request in IntelliJ website – Sam Jun 15 '17 at 06:39
  • I submitted a feature request here: https://intellij-support.jetbrains.com/hc/en-us/requests You can probably do the same. – tir38 Aug 08 '17 at 14:08
0

There might be something else going on. Please check if somewhere in your code you call MyEnum.values()

According to this IDEA bug it's a special request that in that case all enum members are considered used. That's a double edged sword as in some cases it's a smell not to have the enum constant referenced in the code.

Stelios Adamantidis
  • 1,866
  • 21
  • 36