This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline fun <reified T> isA(value: Any) = value is T | |
| >>> println(isA<String>("abc")) | |
| true | |
| >>> println(isA<String>(123)) | |
| false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> fun <T> isA(value: Any) = value is T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T : Number> oneHalf(value: T): Double { | |
| return value.toDouble() / 2.0 | |
| } | |
| >>> println(oneHalf(3)) | |
| 1.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface List<T> { | |
| operator fun get(index: Int): T | |
| // ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> val <T> x: T = TODO() | |
| ERROR: type parameter of a property must be used in its receiver type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val authors = listOf("Dmitry", "Svetlana") | |
| val readers = mutableListOf<String>(/* ... */) | |
| fun <T> List<T>.filter(predicate: (T) -> Boolean): List<T> | |
| >>> readers.filter { it !in authors } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val letters = ('a'..'z').toList() | |
| println(letters.slice<Char>(0..2)) | |
| println(letters.slice(10..13)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Error:(12, 34) Kotlin: Illegal usage of inline-parameter 'predicate' in 'public inline fun inlinedFilter(list: List<Int>, predicate: (Int) -> Boolean): List<Int> defined in functiontypes in file Inline.kt'. Add 'noinline' modifier to the parameter declaration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline fun inlinedFilter(list : List<Int>, predicate : (Int) -> Boolean) : List<Int>{ | |
| val function = predicate | |
| return list.filter(predicate) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static final boolean filterLessThanTwo(int input) { | |
| return input < 2; | |
| } | |
| public static final void lambdaInstanceTest() { | |
| List list$iv = CollectionsKt.listOf(new Integer[]{1, 2, 3}); | |
| Iterable $receiver$iv$iv$iv = (Iterable)list$iv; | |
| Collection destination$iv$iv$iv$iv = (Collection)(new ArrayList()); | |
| Iterator var4 = $receiver$iv$iv$iv.iterator(); |