gpt4 book ai didi

Kotlin @FunctionalInterface 使用多种抽象方法进行编译

转载 作者:行者123 更新时间:2023-12-01 03:08:15 24 4
gpt4 key购买 nike

尝试编译 Java 时 @FunctionalInterface具有超过 1 个非抽象方法会引发编译错误。

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

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

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

请注意,为上述 Kotlin 片段生成的字节码等同于以下 Java 片段(正确地 - 无法编译):
@FunctionalInterface
// metadata omitted
public interface Foo {
void foo();
void foo(@NotNull Map var1);
}

最佳答案

问题 KT-25512已提交给 JetBrains 的问题跟踪器(由另一个用户)报告编译器在 @FunctionalInterface 时出现异常的事实。应用于非 SAM 界面,截至 2019 年 2 月 10 日,该问题仍处于打开状态,没有任何事件。

关于Kotlin @FunctionalInterface 使用多种抽象方法进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54514692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com