dimanche 1 juillet 2018

Type check fails for memberProperty returnType superclass

I've got an instance of an object, which I scan for memberProperties that have a proper annotation attached on them. Then, I want to filter based on their return type. For example if declaration is as follows: class AutoValidatedThing : AutoValidatedUserInputComponent {...} and the target instance contains a @ValidComponent val someProperty: AutoValidatedThing = ..., I'd want to get the someProperty as a AutoValidatedUserInputComponent to the end of the following code block:

    val invalidOnes = this::class.memberProperties
        .filter { it.javaField != null && it.javaField!!.isAnnotationPresent(ValidComponent::class.java) }
        .filter { val annotations = it.javaField?.annotations; annotations != null
                && annotations.map { ann -> ann.annotationClass }.contains(ValidComponent::class)
                && it.returnType is AutoValidatedUserInputComponent }
        .map { it.getter.call() as AutoValidatedUserInputComponent }

But it.returnType is AutoValidatedUserInputComponent ALWAYS returns false.

AutoValidatedUserInputComponent is a simple interface:

interface AutoValidatedUserInputComponent {
    fun blabla() : SomeType
}





Aucun commentaire:

Enregistrer un commentaire