Any.hashCode() and Any?.hasCodeOrDefault(Int) added to standard library

This commit is contained in:
Andrey Breslav
2012-09-07 21:25:44 +04:00
parent df76d2d3a8
commit 57e63a8529
2 changed files with 10 additions and 0 deletions
@@ -47,3 +47,9 @@ public inline fun <T> callable(action: ()-> T): Callable<T> {
public override fun call() = action()
}
}
/**
* A helper method for calling hashCode() on Kotlin objects
* TODO remove when Any supports equals() and hashCode()
*/
public inline fun Any.hashCode(): Int = (this as java.lang.Object).hashCode()
@@ -181,3 +181,7 @@ public inline fun <in T> T?.toSortedList(transform: fun(T) : java.lang.Comparabl
return answer
}
*/
/** Returns a hash code on an existing object, or default value otherwise */
public inline fun Any?.hashCodeOrDefault(default: Int): Int = if (this == null) default else this.hashCode()