Inspectopedia Help

Abstract 'class' may be 'interface'

Reports abstract classes that can be converted to interfaces.

Using interfaces instead of classes is preferable as Java doesn't support multiple class inheritance, while a class can implement multiple interfaces.

A class may be converted to an interface if it has no superclasses (other than Object), has only public static final fields, public abstract methods, and public inner classes.

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.

ClassMayBeInterface
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 | Class structure

Example:

abstract class Example { public static final int MY_CONST = 42; public abstract void foo(); } class Inheritor extends Example { @Override public void foo() { System.out.println(MY_CONST); } }

After the quick-fix is applied:

interface Example { int MY_CONST = 42; void foo(); } class Inheritor implements Example { @Override public void foo() { System.out.println(MY_CONST); } }

Configure the inspection:

Use the Report classes containing non-abstract methods when using Java 8 option to report only the classes with static methods and non-abstract methods that can be converted to default methods (only applicable to language level of 8 or higher).

Inspection options

Here you can find the description of settings available for the Abstract 'class' may be 'interface' inspection, and the reference of their default values.

Report classes containing non-abstract methods when using Java 8

Not selected

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024