Skip to content

Instantly share code, notes, and snippets.

@gjesse
Last active February 25, 2016 16:25
Show Gist options
  • Save gjesse/878a4ea2acc22a7c2a5a to your computer and use it in GitHub Desktop.
Save gjesse/878a4ea2acc22a7c2a5a to your computer and use it in GitHub Desktop.
fun <T> T?.requireNonNull(id: String): T = this ?: throw NullPointerException("%s must be specified".format(id))
@Test
fun testRequireNonNull() {
val isNull: String? = null
val maybeNull: String? = "not really null"
assertThatThrownBy { isNull.requireNonNull("isNull") }
.isInstanceOf(NullPointerException::class.java)
val notNull:String = maybeNull.requireNonNull("maybeNull")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment