Hi guys, i'm trying to pass a generic interface in...
# getting-started
b
Hi guys, i'm trying to pass a generic interface in function param, but i dont understood why not acceptable, my code
Copy code
interface Validator<in T> {
    fun validate(input: T) : Boolean
}

class ValidatorImpl: Validator<String> {
    override fun validate(input: String) = !input.isEmpty()
}

class ValidatorImpl2: Validator<String> {
    override fun validate(input: String) = !input.isEmpty()
}

class Form {
    fun validateForm(validator: Validator) { // 1 problem's here
    }
}
In my case if i change validateForm to receive Validator<Any> when I pass a ValidatorImpl(). I receive a error because ValidatorImpl is not type Any, in Java I simple pass interface, but in kotlin by now without results. Thank you!!!