News for hackers. Stuff that matters.
Re:From Java to Kotlin and Back Again by kjeetgill on Wednesday May 23, 2018 @03:57PM (#17137626)
I'm unfamiliar with Kotlin in detail. Can you explain "Functions are first-class (you can pass functions to functions)"? Are they more powerful than Java's lambdas?
Re:From Java to Kotlin and Back Again by guelo on Wednesday May 23, 2018 @05:15PM (#17138380)
They're slightly different. Kotlin's compiler does some tricks that Java doesn't do to inline lambdas passed to functions. But Kotlin doesn't currently use Java 8's invokedynamic on the JVM, though they're planning to in the future. Not sure about on Dalvik.
Re:From Java to Kotlin and Back Again by forfengeligfaen on Wednesday May 23, 2018 @04:05PM (#17137712)
In Java 7 (which is what I was using) you could not assign a method to a variable or pass it to another method. So I think it is more powerful. https://kotlinlang.org/docs/reference/lambdas.html
Re:From Java to Kotlin and Back Again by cmurdock on Wednesday May 23, 2018 @04:09PM (#17137738)
I think the big use-case is on Android where you're stuck with Java 7 and therefore can't use lambdas.
Re:From Java to Kotlin and Back Again by dlubarov on Wednesday May 23, 2018 @04:13PM (#17137779)
That used to be the case, but the build tools have supported lambdas for a while now, and it works even on very old devices.

On the other hand, Java 8 classes like java.util.Stream only exist on API 24+ devices. So if you want to support older classes, you can't use the standard stream library.

Re:From Java to Kotlin and Back Again by cmurdock on Wednesday May 23, 2018 @04:21PM (#17137858)
Ah interesting. Thanks for the info.
Re:From Java to Kotlin and Back Again by jrs95 on Wednesday May 23, 2018 @04:10PM (#17137750)
Yes, Java lambdas are just syntactic sugar over anonymous classes with a single method IIRC. You must define a full Interface to use when defining the function signature. Kotlin functions are essentially objects that can be passed around, stored in variables, etc. You can also have functions that don’t belong to any class, no need to use static methods for that.
Re:From Java to Kotlin and Back Again by krzyk on Wednesday May 23, 2018 @04:29PM (#17137951)
Not exactly, lambdas use invokedynamic which has different performance characteristics when compared to anonymous classes.

See a talk by Brian Goetz - https://www.youtube.com/watch?v=MLksirK9nnE

Re:From Java to Kotlin and Back Again by jrs95 on Wednesday May 23, 2018 @04:52PM (#17138156)
Great, thank you for the correction. I only knew of what it looked like from an implementation perspective, had no idea things worked differently at runtime.