Eclipse was smart about this; IntelliJ not yet. Of course if a function is unused (and untested, I guess I should feel bad for that - even if it's just returning a simple variable, or implementing someone else's interface) but public, it may be used elsewhere. Looking under Inspections and searching for "unused," I don't see visibility settings. Does this granularity exist?
3 Answers
If you want to highlight unused public methods, please enable the "Settings|Inspections|Declaration redundancy|Unused declaration" global inspection.
If you want to highlight unused private methods, please enable the "Settings|Inspections|Declaration redundancy|Unused symbol" local inspection.
So, if you want to highlight unused private members, but do not highlight unused public members, turn off "Unused declaration" and turn on "Unused symbol".
I've just tested it using IDEA 13.1.4, and it worked exactly as described.
-
2Groan! This setting is gone in IDEA 14.1 (probably disappeared in 14.0). Any suggestions of where to look in 14.1? – Matt Passell Oct 28 '15 at 14:01
-
This setting is gone and the suggested solution seems to turn off the private methods as well. Anybody knows a better way to deal with this issue? – TatiOverflow Nov 27 '15 at 07:01
-
There's a problem report filed and we should vote for it so JetBrains fixes this - https://youtrack.jetbrains.com/issue/IDEA-148321 – trustin Feb 12 '16 at 13:36
-
@trustin: That bug report is now flagged as fixed in version 2016.3. – RenniePet Sep 22 '16 at 03:50
-
this options aren't available for Kotlin? – A1m Feb 08 '20 at 06:24
... for Kotlin
as of IntelliJ IDEA 2017.3.4 (and probably earlier versions), the corresponding setting is:
File | Settings | Editor | Code Style | Inspections | Kotlin | Redundant constructs | Unused symbol
documentation:
This inspection reports classes, functions or properties in the specified inspection scope that are not used or not reachable from entry points.
There is no setting for Unused declaration anymore, so this setting is not for private
and public
symbols alike.
Alternative
Instead of completely turning off warnings about unused symbols, you could use an annotation (possibly defined by yourself), for example @PublicApi
, to mark all function sand classes that you do not want to get warnings for. You then have to add this annotation as an entry point under:
File | Settings | Editor | Code Style | Inspections | Kotlin | Redundant constructs | Unused symbol | Options | Annotations...
You may have to restart the IDE after that.

- 3,615
- 2
- 33
- 41
Turn off this inspection: File -> Settings -> Inspections(under Project Settings) -> Unused declaration(under Declaration redundancy group), move the hook before it.

- 219
- 2
- 11
-
1
-
It will turn off inspection for private method. I don't know how to fix it so far. – yanyu May 29 '14 at 02:36