Skip to content

Instantly share code, notes, and snippets.

@akbarsha03
Last active June 18, 2017 19:37
Show Gist options
  • Save akbarsha03/03dab33a03895e95d3e0171f9ec80592 to your computer and use it in GitHub Desktop.
Save akbarsha03/03dab33a03895e95d3e0171f9ec80592 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
RequestBody(null, 25)
}
data class RequestBody(val name: String?, val age: Int?) {
init {
checkNotNull(name) {
"This can't be null" // Custom message for IllegalStateException
}
checkNotNull(age) // There is a default message too
require(age ?: 0 < 18) { // defenitely not these kind of conditions :P
"Custom message for IllegalArgumentException"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment