# Kotlin - JAVA8

**URL:** <https://discuss.kotlinlang.org/t/kotlin-java8/115>\
**Category:** Uncategorized\
**Created:** [January 29, 2014, 10:52am UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115 "2014-01-29T10:52:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SvenRuppert](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/svenruppert/32/1474_2.png) [@SvenRuppert](https://discuss.kotlinlang.org/u/SvenRuppert)\
**Post date:** [January 29, 2014, 10:52am UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/1 "2014-01-29T10:52:21Z")

</div>

Can I inherid from java interfaces with default methods ?

Greetings sven

---

<div class="post-metadata">

**Author:** ![geevee](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/geevee/32/1475_2.png) [@geevee](https://discuss.kotlinlang.org/u/geevee)\
**Post date:** [January 29, 2014, 1:43pm UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/2 "2014-01-29T13:43:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pniederw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pniederw/32/1428_2.png) [@pniederw](https://discuss.kotlinlang.org/u/pniederw)\
**Post date:** [September 15, 2015, 6:11pm UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/3 "2015-09-15T18:11:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [September 15, 2015, 6:20pm UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/4 "2015-09-15T18:20:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pniederw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pniederw/32/1428_2.png) [@pniederw](https://discuss.kotlinlang.org/u/pniederw)\
**Post date:** [September 16, 2015, 8:23pm UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/5 "2015-09-16T20:23:00Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![salomonbrys](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/salomonbrys/32/1445_2.png) [@salomonbrys](https://discuss.kotlinlang.org/u/salomonbrys)\
**Post date:** [September 17, 2015, 8:13am UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/6 "2015-09-17T08:13:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mplatvoet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mplatvoet/32/7121_2.png) [@mplatvoet](https://discuss.kotlinlang.org/u/mplatvoet)\
**Post date:** [September 17, 2015, 9:08am UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/7 "2015-09-17T09:08:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![salomonbrys](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/salomonbrys/32/1445_2.png) [@salomonbrys](https://discuss.kotlinlang.org/u/salomonbrys)\
**Post date:** [September 17, 2015, 10:33am UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/8 "2015-09-17T10:33:20Z")

</div>

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.

```kotlin
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 ;)

---

<div class="post-metadata">

**Author:** ![pniederw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pniederw/32/1428_2.png) [@pniederw](https://discuss.kotlinlang.org/u/pniederw)\
**Post date:** [September 17, 2015, 1:43pm UTC](https://discuss.kotlinlang.org/t/kotlin-java8/115/9 "2015-09-17T13:43:34Z")

</div>

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.
