The document discusses several Kotlin advanced topics including delegated properties, lazy properties, objects, higher-order functions, lambdas, inline functions, and standard library functions like apply, also, let. It explains concepts like lazy initialization with lazy properties, property delegation, object expressions and declarations, functional programming with higher-order functions and lambdas, and inline functions for performance. It also covers utility functions in the standard library for working with objects and collections.
Convert to study materialsBETA
Transform any presentation into ready-made study material¡ªselect from outputs like summaries, definitions, and practice questions.
37. Inline functions
fun <T> TreeNode.findParentOfType(clazz: Class<T>): T? {
var p = parent
while (p != null && !clazz.isInstance(p)) {
p = p.parent
}
return p as T?
}
38. Inline functions
fun <T> TreeNode.findParentOfType(clazz: Class<T>): T? {
var p = parent
while (p != null && !clazz.isInstance(p)) {
p = p.parent
}
return p as T?
}
45. fun <T> TreeNode.findParentOfType(clazz: Class<T>): T? {
var p = parent
while (p != null && !clazz.isInstance(p)) {
p = p.parent
}
return p as T?
}
Inline functions
inline fun <reified T> TreeNode.findParentOfType(): T? {
var p = parent
while (p != null && p !is T) {
p = p.parent
}
return p as T?
}
46. Other
? Function in?x notation
? Operators overloading
? Tail recursion optimizations
? Local functions
61. @Deprecated
public annotation class Deprecated(
val message: String,
val replaceWith: ReplaceWith = ReplaceWith(""),
val level: DeprecationLevel = DeprecationLevel.WARNING
)
public annotation class ReplaceWith(
val expression: String, vararg val imports: String)
public enum class DeprecationLevel {
WARNING,ERROR,HIDDEN
}
66. Common
? No ternary operator (?:)
? No static members
? No checked exception
? No ¡°switch¡± operator
? Declaration of array type
? Arrays in Kotlin are invariant
? No primitive types
67. Generics
? No raw types
? Declaration-site & User-site variances instead of wildcards
? Only upper bound constraint
68. Classes
? All classes are ?nal by default
? No ?elds
? All functions & properties are ?nal by default
? Nested classes has no access to outer class by default
? Outer class has no access to inner class private members
? No anonymous classes
69. Visibility Modi?ers
? ¡°Visibility modi?ers¡± instead of¡°Access modi?ers¡±
? All members are public by default
? No ¡°package private¡±
? New ¡°internal¡± visibility modi?er