mercredi 7 octobre 2015

Unable to see abstract base class methods via child class instance using Reflection

I have an abstract base class as below and a child class which extends the base class.Now when I get an instance of the child class via spring as below am not able to see the base class methods although all my base class methods are public ones. I try to get all the methods of the object(bean) that I retrieved via spring I don't see the methods defined in my abstract base class .Can somebody let me know what is wrong with this piece of code?

I am only able to see those methods which are explicitly defined in the child class.

//Base abstract class 
    public abstract class A<K, V> implements C<K, V>,CD<K,V> {
       public final V get(final K key){}
       public final V get(String key){}
       public String getValue();

    }
    //Child concrete class 
    public class Q extends A<Long, XYZ> implements QC,
        CD<Long, XYZ> {
     public Class<XYZ> getClass() {}
     public String getValue(){}
    }
    //Code to retrieve the objects using reflection
    final Object someObject = ApplicationContext.getBean("Q");

          for (Method method : someObject.getClass().getDeclaredMethods()) {
                        if (Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0
                            && method.getReturnType() != void.class
                            && (method.getName().startsWith("get") || method.getName().startsWith("is"))) {
                            Object value = method.invoke(someObject);
                            if (value != null) {
                                System.out.println(method.getName() + "=" + value);
                            }
                        }
                    }





Aucun commentaire:

Enregistrer un commentaire