Kotlin: Specify input-constraints in interface
问题 Lets say I have the following interface: interface MathThing { fun mathFunction(x : Int) } Let's say the constraint I want to put onto this function is that x cannot be negative. How can I make sure that every time this (or any other arbitrary) condition isn't met on a object of type MathThing, a (custom) exception is thrown? 回答1: One way is to use a wrapper class for your function parameters. You can make an extension function so it's a little easier to pass values to the function. data