abstract
classes which can be converted to interfaces.
Java doesn't support multiple class inheritance while class can implement multiple interfaces,
so it makes sense to use interfaces wherever possible instead of classes.
A class may be converted to an interface if it has no superclass (other
than Object), has only public static final
fields, public abstract
methods, and public
inner classes.
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 applying the fix:
interface Example {
int MY_CONST = 42;
void foo();
}
class Inheritor implements Example {
@Override
public void foo() {
System.out.println(MY_CONST);
}
}
You can configure the inspection to only report classes containing static
methods and non-abstract methods which can be converted to
default
methods (only applicable to language level of 8 or higher).