【发布时间】:2016-10-20 18:28:24
【问题描述】:
例如,在 Java 中,我可以自己编写 getter(由 IDE 生成)或在 lombok 中使用 @Getter 之类的注解 - 这非常简单。
然而,Kotlin 有 getters and setters by default。 但我不明白如何使用它们。
我想实现它,可以说 - 类似于 Java:
private val isEmpty: String
get() = this.toString() //making this thing public rises an error: Getter visibility must be the same as property visibility.
那么 getter 是如何工作的呢?
【问题讨论】:
标签: kotlin getter-setter