https://kotlinlang.org logo
#getting-started
Title
# getting-started
n

NelsonC

08/28/2022, 7:27 PM
Hello, I'm very new to Kotlin and was wondering if it was possible to make a variable to only fit its string value on a restricted interval. I want to make the user input an hour and if the value of int goes above 24 it displays "Number not valid". Any inputs on this?
t

TarekB

08/28/2022, 7:42 PM
I believe you need to override set property https://kotlinlang.org/docs/properties.html#getters-and-setters
👍 1
g

Giorgos Makris

08/29/2022, 7:28 AM
You could also look into contracts if you want the compiler to force you to check that
👍 1
3 Views