I'm trying to reply this answer Kotlin: Specify input-constraints in interface and my idea was to create a function that implements some validation and allowing the function to be validated to be called only in the context of the validation function. Is it possible? That's my current code:
interface MathThing {
fun mathFunction(x: Int)
}
fun validationContext(x: Int, block: (Int) -> Unit){
require(x > 0)
block(x)
}
fun main() {
val o = object : MathThing {
override fun mathFunction(x: Int) {
println(x)
}
}
validationContext(-1, o::mathFunction)
}