12. ⽂文字
PROPERTIES
▸ var(variable)
▸ var age (compile error)
▸ var age:Int (compile error)
▸ var age = 1 (ok)
▸ age = 2 (ok)
▸ age = null (ok)
▸ var myAge = age (ok)
25. ⽂文字
LAMBDA
▸ Adapter OnItemClickListener in Kotlin
var onOrderItemClickListener : (order: Order) -> Unit
holder?.onClick{
onOrderItemClickListener.invoke(order)
}
holder?.onClick{
onOrderItemClickListener(order)
}
26. ⽂文字
OPERATOR OVERLOADING
▸ a == b -> a.equals(b)
▸ a + b -> a.plus(b)
▸ a - b, a * b, a / b, a % b …..
▸ a..b -> a.rangeTo(b)
▸ a in b -> a.contains(b)
▸ a[i] -> a.get(i)
▸ a[i] = b -> a.set(i, b)
27. ⽂文字
COMPANION OBJECT
class App : Application() {
companion object {
private var instance: Application? = null
fun instance() = instance
}
override fun onCreate() {
super.onCreate();
instance = this
}
}
28. ⽂文字
PROPERTISE DELEGATE
class Delegate<T> : ReadWriteProperty<Any?, T> {
override fun getValue(thisRef: Any?, property : KPropety<*>) {
}
override fun setValue(thisRef: Any?, property : KPropety<*>, value: T) {
}
}
var name : String by Delegate()