https://kotlinlang.org logo
#announcements
Title
# announcements
t

tianhao

10/19/2017, 3:24 AM
The warning is :
Kotlin: Unchecked cast: Array<out Validator> to Array<Validator>
g

greyteardrop

10/19/2017, 5:05 AM
You could change
validators
type to
Array<out Validator>
. Or just merge that field with constructor parameter.
Copy code
class GenericCompositeValidator<T>(private val type: Class<T>,
                                   private vararg val validators: Validator) : Validator {

    override fun supports(clazz: Class<*>): Boolean = type.isAssignableFrom(clazz)

    override fun validate(target: Any, errors: Errors) {
        for (v in validators) {
            v.validate(target, errors)
        }
    }
}
t

tianhao

10/19/2017, 5:22 AM
thanks
that works 👍
8 Views