Default interface methods aren't considered abstract method implementations

Attila Szegedi szegedia at gmail.com
Sun Feb 9 21:04:24 UTC 2025


Hey folks,

I found a somewhat puzzling behavior: default interface methods aren't
considered abstract method implementations. Trying to compile this minimal
reproducer:

------ C.java ------
abstract class A {
  abstract void m();
}

interface F {
  default void m() {}
}

class C extends A implements F {}
------ C.java ------

$ javac C.java
C.java:9: error: C is not abstract and does not override abstract method
m() in A
class C extends A implements F {
^
1 error

I can accept this being valid according to JLS today (I tried with 11, 21,
and 23.) I admit this is one of rare occasions when I didn't go scouring
the JLS to figure out what exactly prevents the compiler from accepting
F.m() as implementation of A.m() in C. I'm wondering though if this isn't
something that could be improved upon in the future. (I'm sure there's a
gotcha somewhere. Right, Brian? ;-) )

Have a great day,
  Attila.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20250209/68666c9c/attachment.htm>


More information about the jdk-dev mailing list