January 2018
Intermediate to advanced
434 pages
14h 1m
English
Let's follow these steps to understand how custom getter-setters work in Kotlin:
var <propertyName>[: <PropertyType>] [= <property_initializer>] [<getter>] [<setter>]
So if you use something like val a =1, you get a default getter and setter.
fun main(args: Array<String>) { val sample=Sample() println(sample.isListBig)}class Sample{ val array= mutableListOf<Int>(1,2,3) val isListBig:Boolean get()=array.size>2}
If you run the preceding code, you'll see the output in the console as follows:
Read now
Unlock full access