Hey guys! I'd like to discuss the following syntax...
# codereview
l
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
I strongly prefer the first, because it's clearer (or even necessary) in case of overloads
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
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
👍 1