Get the App
SLTechnology News&Howtos  ›  Development  › 

How Kotlin customizes Getters/Setters

Shulou Source: shulou.com Published: 2022-06-01 04:24:27 10月03日 Update

This article will explain in detail how to customize Getters/Setters for Kotlin. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Custom Getters/Setters

Kotlin will automatically use the getter/setter model, but there are some cases (such as Json) that we need to use custom getter and setter. For example:

@ ParseClassName ("Book") class Book: ParseObject () {/ / getString () and put () are methods that come from ParseObject var name: String get () = getString ("name") set (value) = put ("name", value) var author: String get () = getString ("author") set (value) = put ("author", value)} this is the end of the article on "how Kotlin customizes Getters/Setters". I hope the above content can be helpful to you. So that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Articles more good practical content situation articles models knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB Redmi Huawei vpn