Defaut methods are not visible if -source 1.7 is set

Markus Keller markus_keller at ch.ibm.com
Fri Nov 1 13:55:47 PDT 2013


Dan Smith wrote:

> The problem is that _implementing_ an interface is a different use case 
than _using_ an interface.

Exactly. The compatible behavior for javac8 / ecj8 with -source 1.7 is to:

(1) skip default methods when checking whether a class has abstract 
methods that need to be implemented, and
(2) consider default methods as abstract when calling or overriding a 
method

There is no one-choice-fits-all solution for the two viewpoints.

The given solution works fine as long as the 1.7 source doesn't make use 
of 1.8-only APIs. Otherwise, it's like when supposedly-1.7 source code 
calls an ordinary @since 1.8 method: Works fine when running with a 1.8 
JRE, but fails with a 1.7 JRE.

For those who are into contracts:
Turning an abstract method into a default method strengthens the 
postcondition (default method provides more than an abstract method). 
Strengthening a postcondition is a breaking change for implementers (1), 
but it's fine for callers (2). In Java 8, the incompatibility for 
implementers is lifted by the special inheritance rules for default 
methods (which hide the default implementation unless no other 
implementation is available). javac8 / ecj8 with -source 1.7 need to adapt 
these special inheritance rules to the "mixed source level" situation.

Markus



More information about the lambda-spec-observers mailing list