【问题标题】:Kotlin @FunctionalInterface compiles with multiple abstract methodsKotlin @FunctionalInterface 使用多种抽象方法进行编译
【发布时间】:2019-02-04 10:58:54
【问题描述】:

当尝试编译具有多个非抽象方法的 Java @FunctionalInterface 时,会引发编译错误。

但是,在 Kotlin 中执行相同操作时,不会引发错误或警告,即以下 Kotlin interface 编译成功:

@FunctionalInterface
interface Foo {
    fun foo()
    fun foo(params: Map<String, String>)
}

这是 Kotlin 编译器的预期行为还是错误?

请注意,为上述 Kotlin sn-p 生成的字节码等同于以下 Java sn-p(正确 - 无法编译):

@FunctionalInterface
// metadata omitted
public interface Foo {
   void foo();
   void foo(@NotNull Map var1);
}

【问题讨论】:

    标签: kotlin functional-interface


    【解决方案1】:

    问题 KT-25512 已提交给 JetBrains 的问题跟踪器(由另一位用户),以报告当 @FunctionalInterface 应用于非 SAM 接口时编译器行为异常,截至 2019 年 2 月 10 日问题仍然存在打开时没有任何活动。

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多