Enum, interfaces and (Java 8) lambdas: code compiles but fails at runtime; is this expected?
- 阅读更多 关于 Enum, interfaces and (Java 8) lambdas: code compiles but fails at runtime; is this expected?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: JDK is Oracle' JDK 1.8u65 but the problem has been seen with "as low as" 1.8u25 as well. Here is the full SSCCE: public final class Foo { private interface X { default void x () { } } private enum E1 implements X { INSTANCE , ; } private enum E2 implements X { INSTANCE , ; } public static void main ( final String ... args ) { Stream . of ( E1 . INSTANCE , E2 . INSTANCE ). forEach ( X :: x ); } } This code compiles; but it fails at runtime: Exception in thread "main" java . lang . BootstrapMethodError : call site initialization