Hey guys!
I'd like to discuss the following syntaxes:
Copy code
fun insertAll(uses: Iterable<Use>) {
uses.forEach { insert(it) }
uses.forEach(::insert)
}
What do you think about both approaches?
e
ephemient
04/03/2022, 5:05 PM
I strongly prefer the first, because it's clearer (or even necessary) in case of overloads
ephemient
04/03/2022, 5:07 PM
note that due to various reasons, the two don't compile to the same code in the non-inline case:
{ insert(it) } != { insert(it) }
which makes it easy for the compiler to create a wrapper, but
::insert == ::insert
which means the compiler has to do some more work to produce a stable reference
👍 1
ephemient
04/03/2022, 5:08 PM
also the former can be compiled to modern indy lambdas but the latter cannot be for historical compatibility reasons (related to the above), https://youtrack.jetbrains.com/issue/KT-45658