Tutorial by Examples

To obtain a reference to a KClass object representing some class use double colons: val c1 = String::class val c2 = MyClass::class
Functions are first-class citizens in Kotlin. You can obtain a reference on it using double colons and then pass it to another function: fun isPositive(x: Int) = x > 0 val numbers = listOf(-2, -1, 0, 1, 2) println(numbers.filter(::isPositive)) // [1, 2]
To obtain a Java's Class object from Kotlin's KClass use the .java extension property: val stringKClass: KClass<String> = String::class val c1: Class<String> = stringKClass.java val c2: Class<MyClass> = MyClass::class.java The latter example will be optimized by the compile...
Given Example class extending BaseExample class with some properties: open class BaseExample(val baseField: String) class Example(val field1: String, val field2: Int, baseField: String): BaseExample(baseField) { val field3: String get() = "Property without backing ...
As an example we want to set all string properties of a sample class class TestClass { val readOnlyProperty: String get() = "Read only!" var readWriteString = "asd" var readWriteInt = 23 var readWriteBackedStringProperty: String = "" ...

Page 1 of 1