A few months ago I’ve started to discover Jetbrains’ Kotlin language which gave a good impression to me. I can't express my thoughts better than th...
For further actions, you may consider blocking this person and/or reporting abuse
I love just about everything I have seen from Kotlin, but the snippet you added can be closely replicated in Java 8:
Actually, the java example is better, since the lambda is lazily evaluated.
putIfAbsent
will always try to construct it's second argument even if it isn't in the map. However, that doesn't mean you can't use it in kotlin as well.Hi Evan, thank you for this snippet! I wasn't familiar with computeIfAbsent method. :)
No problem! It is amusing watching Java add a lot of these kinds of features from Scala and Kotlin.
Java 9 will also have some nice factory methods, so you will probably be able to write something like...
Map map = Map.of("aaa", List.of(32) );
I don't think that this is a good example, this hacker type/python style code is not good for anyone, is hard to understand, maintain, extend, catch errors and so on. The first snippet can be understood by most engineers that worked in any C like language, the 2nd ...probably under 10%.
I'm more interested when Kotlin will be able to build iOS apps, then it will be on my radar (shooting 2 platforms with 1 language).
Excuse me are you saying that all Python Programmers are hackers that write bad code that is hard to understand, maintain, extend, catch errors etc?
I see 2 identical code snippets...
Ok, I see it's been fixed.
Not for me, I still see the Lazymap.java twice
It may be something wrong with the dev.to platform. Looks like it's serving previous versions of the post occasionally. Sometimes I'm getting this post loaded without the second snippet at all.