我有一个对象的实例,我会扫描它以查找附加了正确注释的 memberProperties。然后,我想根据它们的返回类型进行过滤。例如,如果声明如下:class AutoValidatedThing : AutoValidatedUserInputComponent {...}
并且目标实例包含 a @ValidComponent val someProperty: AutoValidatedThing = ...
,我希望将someProperty
as aAutoValidatedUserInputComponent
放在以下代码块的末尾:
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 }
但it.returnType is AutoValidatedUserInputComponent
总是返回 false。
AutoValidatedUserInputComponent
是一个简单的界面:
interface AutoValidatedUserInputComponent {
fun blabla() : SomeType
}