Kotlin - JAVA8

Can I inherid from java interfaces with default methods ?

Greetings sven

Java 8 interoperability is not going to be supported before it is released. Anyway, some features may work accidentally. I suppose that default methods may be treated as usual abstract methods.

When is this going to be fixed? I don't seem to be able to call Map::getOrDefault in Kotlin M12. Not being able to call Java 8 default methods is a big limitation.

If I'm not mistaken, this is fixed in M13.

I just updated to M13. I'm able to call default methods in general, but can't call Map::getOrDefault. I see that there is no such method on kotlin.Map. Can't tell if there is a deeper reason for this, hope it will get fixed soon.

Anyway, congrats on a great release! Renews me high hopes in Kotlin.

PS: Class search doesn’t find kotlin.Map or kotlin.MutableMap, does find kotlin.MutableMapWithDefault (15 EAP).

I don't think kotlin.map needs a getOrDefault method since kotlin has a language construct for this :

val value = map[key] ?: defaultValue

or

val value = map.get(key) ?: defaultValue


That wouldd be suitable for most people 99.9999% of the time. There's is only that rare case where someone has `null` as a stored value and an non-null value as the default where they would differ. Darn corner cases.

People who put null in collections deserve to burn just a little less than those who thought it would be a good idea to allow Java collections to contain nulls X-( :p.

public fun <K: Any, V: Any> Map<K, V>.getOrDefault(key: K, default: V): V? = if (key in this) get(key) else default

This is a fairly extension function. And since it is for a corner case, I'm not sure it is necessary to include it in the standard library. I would certainly not use it, but maybe it's less of a corner case than I believe ;)

Since the Kotlin collections compiler illusion is applied automatically even when working directly with Java code, I expect it to expose all methods of the underlying Java collections, without exception. Anything else seems too intrusive, and not in line with Kotlin's pragmatic and Java-friendly approach. Currently, all the default methods added in JDK 8 seem to be missing.