4

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 in FuncE0, 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;
  }
}
4

1 回答 1

0

这是一个已修复的 jdk 错误1.8.0_171(可能不是最低修复版本)。

于 2018-12-03T17:58:50.780 回答