Kotlin     PHP       WEB       3GL   4GL   5GL      

Kotlin

(inline) Kotlin

: -, , -, , , . ( , ) .

" " () -. , lock() , :

lock(l) { foo() }

, - :

l.lock()
try {
    foo()
}
finally {
    l.unlock()
}

, ?

, lock inline:

inline fun lock<T>(lock: Lock, body: () -> T): T {
    // ...
}

inline , , : .

, ( ), , .

noinline

, , , inline- , noinline -, :

inline fun foo(inlined: () -> Unit, noinline notInlined: () -> Unit) {
    // ...
}

inline-, , noinline- : , - ..

, inline- inline , , , ( , , ).

return

Kotlin , return . , label. return , .

fun foo() {
    ordinaryFunction {
        return // ERROR: can not make `foo` return here
    }
}

, , return , :

fun foo() {
    inlineFunction {
        return // OK: the lambda is inlined
    }
}

return ( , ) (non-local). , inline-:

fun hasZeros(ints: List<Int>): Boolean {
    ints.forEach {
        if (it == 0) return true // returns from hasZeros
    }
    return false
}

, inline- , , . , . , crossinline:

inline fun f(crossinline body: () -> Unit) {
    val f = object: Runnable {
        override fun run() = body()
    }
    // ...
}
`break` and `continue` are not yet available in inlined lambdas, but we are planning to support them too-->

break continue ,

, :

fun <T> TreeNode.findParentOfType(clazz: Class<T>): T? {
    var p = parent
    while (p != null && !clazz.isInstance(p)) {
        p = p?.parent
    }
    @Suppress("UNCHECKED_CAST")
    return p as T
}

, . , :

myTree.findParentOfType(MyTreeNodeType::class.java)

, , :

myTree.findParentOfType<MyTreeNodeType>()

inline- (reified type parameters). , - :

inline fun <reified T> TreeNode.findParentOfType(): T? {
    var p = parent
    while (p != null && p !is T) {
        p = p?.parent
    }
    return p as T
}

reified, , . , !is as . , , : myTree.findParentOfType<MyTreeNodeType>()

, :

inline fun <reified T> membersOf() = T::class.members

fun main(s: Array<String>) {
    println(membersOf<StringBuilder>().joinToString("\n"))
}

( ) . , (, Nothing) .

.

Kotlin     PHP       WEB       3GL   4GL   5GL         w  

, , Collaboration diagrams - - , , . , , -. , .




 10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _.
10.11.2021 - 12:36: - Conscience -> . ? - _.
10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _.
10.11.2021 - 12:35: - Ecology -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> . - _.
10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _.
10.11.2021 - 09:18: - New Technologies -> , 5G- - _.
10.11.2021 - 09:18: - Ecology -> - _.
10.11.2021 - 09:16: - Ecology -> - _.
10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _.
10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _.
Bourabai Research -  XXI Bourabai Research Institution