我在 Kotlin 的 paint class 文档中找不到 paint 属性的名称

I cant find the names of paint properties in the documentation of the paint class in Kotlin

所以我找到了这个例子:https://discuss.kotlinlang.org/t/variable-shadowing-and-the-proper-use-of-apply/1407

提供了更改 Paint 对象的不同属性的各种方法。看来,在Kotlin中使用apply函数很方便...

fun makePaint1(_color: Int, _textSize: Float, _strokeWidth: Float, _isAntiAlias: Boolean) =
        Paint().apply {
            color = _color
            isAntiAlias = _isAntiAlias
            textSize = _textSize
            strokeWidth = _strokeWidth
        }

但现在我的问题是:我假设存在一个包含所有 属性 名称的列表,例如: “颜色” “isAntiAlias” “字体大小” “笔画宽度” (希望他们叫属性个名字)

但是在 Paint 的文档中 Class...(https://developer.android.com/reference/kotlin/android/graphics/Paint#ANTI_ALIAS_FLAG:kotlin.Int) ... 例如,当您查找“strokeWidth”时。您只找到两个 public 方法 getStrokeWidth() 和 setStrokeWidth() 并且两个描述实际上都没有提到名称“strokeWidth”。

class 个属性的名称列表是否存在?

Kotlin 有一个叫做 属性 访问语法 的东西,这基本上意味着它翻译 getter 和 setter 方法(比如 getStrokeWidth()setStrokeWidth() 所以它们看起来像 属性 - 一个你可以像任何 valvar 一样读写的字段。如果你不使用它通常会抱怨这个!

所以不,这些属性实际上并不存在于 Paint class - 它们只是糖,由任何存在的 getThing 方法生成(并且它们是如果 setThing 也存在则可写)。

它也会对其他一些人做同样的事情,比如 isDither() (isThing) 这是一个 getter 而 returns 一个布尔值.等效的 setter 是 setDither(boolean) 但 Kotlin 创建了一个 isDither 属性 你可以读写。对于使用 put()get() 方法的事物,您会看到相同的情况 - 我们鼓励您像访问数组一样访问它们,因此 collection[item] 而不是 collection.get(item).