马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
About Property Delegate
property delegate enable you get or set a property value
by DelegateObject.getValue or DelegateObject.setValue
in this way, Delegate object can be reused in similar places
Sources
- fun main() {
- val hello = Hello()
- hello.name = "tom"
- println(hello.name)
- }
- class Hello {
- var name: String by Delegate()
- }
- class Delegate {
- private var value = ""
- operator fun getValue(thisRef: Any, property: KProperty<*>): String {
- return "${thisRef.javaClass.simpleName}::${property.name}=${value}"
- }
- operator fun setValue(thisRef: Any, property: KProperty<*>, value: String) {
- this.value = value
- }
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |