Description
As stated in the guide:
Default methods are backported by copying the default methods to a companion class (interface name + "$") as static methods, replacing the default methods in the interface with abstract methods, and by adding the necessary method implementations to all classes which implement that interface.
If I have this interface:
public interface TestI {
default void test() {}
}
and this class:
public class TestC implements TestI {}
as far as I understand the output of retrolambda will be:
- An interface with an abstract method test
- A new class with a static method (empty in the example)
- The class TestC with the implemented test method
So, If then I have a new class:
public class Test2 {
static {
new TestC().test();
}
}
This should work. Am I right?
I'm asking this because it doesn't.
Test2.java:3: error: cannot find symbol
new TestC().test();
^
symbol: method test()
location: class TestC
If I decompile I found:
public abstract interface TestI {
public abstract void test();
}
public class TestI$ {
public static void test(TestI paramTestI) {}
}
and:
public class TestC implements TestI {}
I don't think the last one is right. I'm doing something wrong or I didn't understand the section:
by adding the necessary method implementations to all classes which implement that interface.
If I use javap I obtain
public class TestC implements TestI {
public TestC();
public void test();
}
So the method is there but as the decompiler cannot find it neither javac does.
I tried both using compatibility with bytecode 50 and 51 using the latest version.
java -Dretrolambda.defaultMethods=true -Dretrolambda.bytecodeVersion=50 -Dretrolambda.inputDir=. -Dretrolambda.classpath=. -jar retrolambda.jar
You can reproduce it by using the same source code
Of course it would be nice if my TestC has all the implementation so that I can use it in other java7 project.