gpt4 book ai didi

Java 互操作 : Apply @JvmName to getters of properties in interface or abstract class

转载 作者:IT老高 更新时间:2023-10-28 13:42:16 34 4
gpt4 key购买 nike

通常我们可以在kotlin中编写如下代码:

val hasValue : Boolean
@JvmName("hasValue") get() = true

这将为 Java interop 生成方法 hasValue() 而不是 getHasValue()

但是,在界面中,这给了我一个编译错误:

val hasValue : Boolean
@JvmName("hasValue") get

抽象类中的以下声明也是如此:

abstract val hasValue : Boolean
@JvmName("hasValue") get

所以这是我的问题:如何告诉 kotlin 编译器使用 hasValue() 而不是 getHasValue() 来获取 a 中属性的 getter(和 setter) kotlin 接口(interface)?

最佳答案

有一个解决方法,请参阅:https://youtrack.jetbrains.com/issue/KT-31420

只需使用注释抑制此 INAPPLICABLE_JVM_NAME 错误:@Suppress("INAPPLICABLE_JVM_NAME")

关于Java 互操作 : Apply @JvmName to getters of properties in interface or abstract class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47504279/

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