当尝试编译具有多个非抽象方法的Java @FunctionalInterface
时,会引发编译错误。
但是,在Kotlin中执行相同操作时,不会引发任何错误或警告,即以下Kotlin interface
成功编译:
@FunctionalInterface
interface Foo {
fun foo()
fun foo(params: Map<String, String>)
}
这是Kotlin编译器中的预期行为还是bug?
请注意,上面的Kotlin代码段生成的字节码与以下Java代码段等效(正确地-不能编译):
@FunctionalInterface
// metadata omitted
public interface Foo {
void foo();
void foo(@NotNull Map var1);
}
答案 0 :(得分:2)
问题KT-25512已提交给JetBrains的问题跟踪器(由另一位用户),以报告自@FunctionalInterface
应用于非SAM界面时到2019年2月10日,编译器行为异常问题仍然存在,没有任何活动。