文件
MinimalBible/app/src/main/kotlin/org/bspeice/minimalbible/CommonUtil.kt
Bradlee Speice 3721ef5ee0 Download and search indexes
Search currently not yielding results, but everything surrounding it appears to be working.
2015-01-18 00:37:44 -05:00

12 行
431 B
Kotlin

package org.bspeice.minimalbible
/**
* Massive credit over here:
* http://blog.omalley.id.au/2013/07/27/null-handling-in-kotlin.html
*
* The trick is that a non-nullable upper bound is placed on an optional
* nullable object - effectively, you get the real object or throw an exception.
*/
public fun <T : Any> T?.orError(message: String): T {
return if (this == null) throw IllegalArgumentException(message) else this
}