I want to programmatically check if a variable I declared using the by Delegates.notNull() has been declared in my code.
val max = arr.maxOrNull()
var num by Delegates.notNull<Int>()
if (max != null) {
if(max >= 0){
for(i in 1..max){
if (!arr.contains(i)){
num = i
break
}
}
if(!(this::num.isInitialized)) num = max + 1 //TODO: How do I check if num variable has been initialized
}
}
return num
I have tried to use the class::num.isInitialized method, but the method I am creating is not in a class; it's just a solution to an algorithm. I also tried creating a class for the solution and making the num variable a field variable; so that I can access it in the class, and this context can work. But it seems the class::num.isInitialized is only used for lateinit variables, and I can't use lateinit var num: Int because you can't use lateinit for primitive datatypes.