继承对象的Java验证
如果我有继承对象的Java验证,java,inheritance,interface,Java,Inheritance,Interface,如果我有 class parent(){} class child() extends parent{} class child2() extends parent{} 那我有 List<parent> // where i store all the child1 & child2 objects 由于child1和child2有不同的字段,是否可以使用一个验证器检查两个孩子,还是需要两个验证器,每个类一个?取决于您尝试验证的内容。切题相关:您的。 Re
class parent(){}
class child() extends parent{}
class child2() extends parent{}
那我有
List<parent> // where i store all the child1 & child2 objects
由于child1和child2有不同的字段,是否可以使用一个验证器检查两个孩子,还是需要两个验证器,每个类一个?取决于您尝试验证的内容。切题相关:您的。
RequiredValidator.validate(List<parent> classToValidate){
// here I use reflection to check for @Size @NotNull Annotations
// i.e
Field[] declaredFields = classToValidate.get(0).getClass().getDeclaredFields();