gpt4 book ai didi

android - 为什么有些 Java setter 方法会自动成为 Kotlin 属性,而有些则不会?

转载 作者:行者123 更新时间:2023-11-29 16:47:12 25 4
gpt4 key购买 nike

例如这个WebSettings Java类。

它有一个 Java 方法 setJavaScriptEnabled(boolean) 变成了一个 Kotlin 属性 javaScriptEnabled 如下,但也有 setSupportZoom(boolean) 不会变成 Kotlin 属性 supportZoom

        settings.javaScriptEnabled = true
settings.domStorageEnabled = true
settings.setSupportZoom(false)
settings.builtInZoomControls = false
settings.setSupportMultipleWindows(true)

最佳答案

来自documentation :

Boolean accessor methods (where the name of the getter starts with is and the name of the setter starts with set) are represented as properties which have the same name as the getter method.

从 Kotlin 1.2.0 开始:

Note that, if the Java class only has a setter, it will not be visible as a property in Kotlin, because Kotlin does not support set-only properties at this time.

签名boolean isSupportMultipleWindows()boolean supportMultipleWindows() 的Java 类中没有方法与 Kotlin 中的属性表示不匹配。

关于android - 为什么有些 Java setter 方法会自动成为 Kotlin 属性,而有些则不会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47545585/

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