Kotlin 2 · Basics and null safety
Validate arguments and state
require checks arguments and check verifies state, both throwing on failure.
fun withdraw(amount: Int) {
require(amount > 0) { "amount must be positive" }
check(balance >= amount) { "insufficient funds" }
}
Official Kotlin 2 documentation