Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/02/2017, 22:49
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: Problemas con Reflection al usar herencias

Hola a todos, les cuento que pude hacer con herencias sin atributos en las subclases

Código Java:
Ver original
  1. private LinkedList<Object>loadMethods(IPersistente ip) throws Exception{
  2.         LinkedList<Method> m = new LinkedList();        
  3.         Child s = ip.getClass().getAnnotation(Child.class);
  4.         Method[] me = null;
  5.         if(s != null && ip.getId() == 0){
  6.             me = ip.getClass().getSuperclass().getDeclaredMethods();
  7.         } else {
  8.             me = ip.getClass().getDeclaredMethods();
  9.         }
  10.         for(Method campo : me){            
  11.             if (campo.getName().startsWith("get") && !campo.getName().startsWith("getClass")) {
  12.                 Method metodo = campo;
  13.                 if(metodo.getParameterCount() == 0) {
  14.                     if(metodo.isAnnotationPresent(Sort.class)){
  15.                         m.add(metodo);
  16.                     }
  17.                 }
  18.             }            
  19.         }
  20.         if(ip instanceof IDependiente && !ip.check()){
  21.             Collections.sort(m, new SortDesc());
  22.         } else {
  23.             Collections.sort(m, new SortAsc());
  24.         }
  25.         return load(ip, m);
  26.     }

Pero cuando se trata de una herencia donde la subclase además de heredar los atributos de la superclase, tiene los suyos no anda No value specified for parameter 1.

Espero sus respuestas y saludos.