Kotlin:公共获取私有集变量 [英] Kotlin : Public get private set var
本文介绍了Kotlin:公共获取私有集变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在kotlin中定义具有公共getter和私有(只能在内部修改的)setter的var的正确方法是什么?
What is the correct way to define a var in kotlin that has a public getter and private (only internally modifiable) setter?
推荐答案
var setterVisibility: String = "abc" // Initializer required, not a nullable type
private set // the setter is private and has the default implementation
请参阅:属性获取器和设置器
这篇关于Kotlin:公共获取私有集变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文