Inspectopedia Help

Use of concrete class

Reports usages of concrete classes, rather than interfaces. Such declarations may represent a failure of abstraction and may make testing more difficult.

Declarations whose classes come from system or third-party libraries will not be reported by this inspection. Casts, instanceofs, and local variables are not reported in equals() method implementations. Also, casts are not reported in clone() method implementations.

Example:

interface Entity {} class EntityImpl implements Entity {} void processObject(Object obj) { // warning: instanceof of the concrete class if (obj instanceof EntityImpl) { // warning: cast to the concrete class, // rather than the interface processEntity((EntityImpl)obj); } } // warning: parameter of concrete class void processEntity(EntityImpl obj) { }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

UseOfConcreteClass
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Abstraction issues

Use the Ignore abstract class type option to ignore casts to abstract classes.

Use the subsequent options to control contexts where the problem is reported.

Inspection options

Here you can find the description of settings available for the Use of concrete class inspection, and the reference of their default values.

Ignore abstract class type

Not selected

Ignore Java records

Default: Selected

Report method return type

Default: Selected

Report method parameter type

Default: Selected

Report local variable type

Default: Selected

Report static field type

Default: Selected

Report instance field type

Default: Selected

Report type used in instanceof, patterns, or getClass() comparison

Default: Selected

Report type used in cast expression

Default: Selected

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024