10/31/2023 0 Comments Any kotlin exampleSo we can say it’s a little more efficient, but honestly, nothing to worry about. With the function references, we’re saving ourselves from a couple of variable declarations, which correspond to the it variables inside the lambdas. Unsurprisingly, the code is pretty similar. String var10 = ((MediaItem)item$iv$iv).getUrl() $receiver$iv = (Iterable)((List)destination$iv$iv) Īnd this for the one with function references: Iterable $receiver$iv = (Iterable)items $receiver$iv = (Iterable)CollectionsKt.sortedWith($receiver$iv, (Comparator)(new HomeContentFragmentKt$getSortedUrls$$inlined$sortedBy$1())) Ĭollection destination$iv$iv = (Collection)(new ArrayList(llectionSizeOrDefault($receiver$iv, 10))) This is the bytecode for the one with explicit lambdas: Iterable $receiver$iv = (Iterable)items So let’s use the Kotlin bytecode tool for the previous example and check it out. You might be wondering if there’s any difference in bytecode, and if one of the options is more efficient than the other. You can declare a function in a variable like this: val sum: (Int, Int) -> Int = Looking at the bytecode This is the main feature to consider that a language supports functional programming style, and Kotlin of course allows this. You already know that Kotlin supports functions as a type, what means that you can save a function in a variable, use it as another function argument, or even make that a function returns another function. Function references are another of those great improvements that we get with Kotlin, which are kind of exotic when we come from Java.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |