Re:Java's records, Lombok's data, and Kotlin's data classes
by valenterry on Sunday May 09, 2021 @06:46AM
(#27094910)
> The only think missing is persistent immutable collections, which are implemented in kotlinx.
You said:
> You have to litter your whole code with `.asScala` and `.asJava`, the java collections don't work with for comprehensions, etc.
So how does kotlinx achieve zero-cost compatibility with Java collections without having something like `.asKotlin` and `.asJava`? Because otherwise there is no difference between Scala and Kotlin in this regards.
Re:Java's records, Lombok's data, and Kotlin's data classes
by joshlemer on Sunday May 09, 2021 @04:50PM
(#27099598)
because the persistentList/Collection/etc in kotlinx implement the appropriate java collection interfaces:
import java.util.List;
public class Foo {
public static void blah(List<Integer> list) {
}
}
Kotlin: import kotlinx.collections.immutable.persistentListOf
fun main(): Unit {
Foo.blah(persistentListOf(1,2,3))
}
This compiles fine
Kotlin:
Kotlin even has a similar take to Scala's views, which they call sequences: Is this really so "lacking in capability and grace" compared to Scala? The only think missing is persistent immutable collections, which are implemented in kotlinx.