allow nullable expressions to be used for lazily creating new items if there is not a value in the Map

This commit is contained in:
James Strachan
2012-09-12 14:56:28 +01:00
parent 6822d9496f
commit bcec41c779
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ val <K,V> Map.Entry<K,V>.value : V
*
* @includeFunctionBody ../../test/MapTest.kt getOrElse
*/
public inline fun <K,V> Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
public inline fun <K,V> Map<K,V>.getOrElse(key: K, defaultValue: ()-> V?) : V? {
val current = this.get(key)
if (current != null) {
return current
+1 -1
View File
@@ -184,7 +184,7 @@ class CollectionTest {
assertEquals(4, byLength.size())
val l3 = byLength.getOrElse(3, {ArrayList<String>()})
assertEquals(2, l3.size)
assertEquals(2, l3?.size)
}
test fun makeString() {