Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
继承对象的Java验证_Java_Inheritance_Interface - Fatal编程技术网

继承对象的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();