To prevent to be closed as duplicate, this question is totally different with this one.
Consider I have the following interface
@FunctionalInterface
interface FuncE0<R, E extends Exception> {
R call() throws E;
}
It works fine with lambda
FuncE0<Integer, IOException> get() {
return () -> 1;
}
But if I let the interface extends from Callable
, it breaks.
@FunctionalInterface
interface FuncE0<R, E extends Exception> extends Callable<R> {
@Override
R call() throws E;
}
With the same usage. Complier gives me following error
JustTest.java:8: error: call() in <anonymous JustTest$> cannot implement call() in FuncE0
return () -> 1;
^ overridden method does not throw Exception
- If you remove the override method
R call() throws E
inFuncE0
, it works. - If you use anonymous class, it works.
- If you use eclipse, ECJ works.
What happened when I override the exception thrown? Is this a javac bug?
I'm using jdk_1.8_112
Minimize code to reproduce
import java.io.IOException;
import java.util.concurrent.Callable;
public class JustTest {
public static FuncE0<Integer, IOException> get() {
return () -> 1;
}
@FunctionalInterface
public interface FuncE0<R, E extends Exception> extends Callable<R> {
@Override
R call() throws E;
}
}