Inspectopedia
 
2024.3

Unused declaration

Warning
Last modified: 03 December 2024

Reports classes, methods, or fields that are not used or unreachable from the entry points.

An entry point can be a main method, tests, classes from outside the specified scope, classes accessible from module-info.java, and so on. It is possible to configure custom entry points by using name patterns or annotations.

Example:

In this example, Department explicitly references Organization but if Department class itself is unused, then inspection will report both classes.

The inspection also reports parameters that are not used by their methods and all method implementations and overriders, as well as local variables that are declared but not used.

Note: Some unused members may not be reported during in-editor code highlighting. For performance reasons, a non-private member is checked only when its name rarely occurs in the project. To see all results, run the inspection by selecting Code | Inspect Code or Code | Analyze Code | Run Inspection by Name from the main menu.

Use the visibility settings below to configure members to be reported. For example, configuring report private methods only means that public methods of private inner class will be reported but protected methods of top level class will be ignored.

Use the entry points tab to configure entry points to be considered during the inspection run.

You can add entry points manually when inspection results are ready.

If your code uses unsupported frameworks, there are several options:

  • If the framework relies on annotations, use the Annotations... button to configure the framework's annotations.

  • If the framework doesn't rely on annotations, try to configure class name patterns that are expected by the framework.

This way the annotated code accessible by the framework internals will be treated as used.