Last active
June 18, 2017 19:37
-
-
Save akbarsha03/03dab33a03895e95d3e0171f9ec80592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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