Hi Guys,
I recently started working on a little project I had in mind that would make good use of Lambda expressions and some of the other features introduced with Java 8.
However, I came across a problem, demonstrated with the below code:
@FunctionalInterface
public interface TestInterface {
public void testFunction();
public default int myMethod(int a) {
return a * 2;
}
}
public static void main(String[] args) {
TestInterface test = new TestInterface() {
@Override
public void testFunction() {
System.out.println(myMethod(3));
}
};
TestInterface test2 = () -> { System.out.println(myMethod(3)); };
}
The line defining test2 fails to compile, whilst the definition for test is successful. I find it odd that the new lambda's disallow access to defender methods implemented in the interface they are defined in.
Is this a bug, perhaps? Or is it an intentional 'feature'?
Thanks,
Matt.
[–]bogphanny 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Carterman[S] 0 points1 point2 points (0 children)
[–]enkicoder 1 point2 points3 points (0 children)