mercredi 29 juillet 2015

getMethods Reflection API result is ambiguous with Interface

Please have a look on the scenario and suggest how can I remove the following issue.

  1. We have an interface BaseRepository which is already build in having a method commitData(), retrieveData(), sortByLength().

     public interface BaseRepository{
           public void commitData();
           public Object retrieveData();
           public Object sortByLength();
        }
    
  2. Interface FileRepository which extends BaseRepository having methods commitData(), fileNames() i.e.

    public interface FileRepository extends BaseRepository{
                public void commitData();
                public List fileNames();
            }
    
  3. Interface ObjectRepository which extends both BaseRepository and FileRepository with no methods in it.

  4. Using Java Reflection API I try to get the methods define in the Interfaces for further processing, but getting method commitData 2 times i.e. following piece of code will give me 2 time commitData in the console

    for(Method method : ObjectRepository.class.getMethods()){
                System.out.println(method.getName());
            }
    

output is:

commitData retrieveData sortByLength commitData fileNames

I am using Java 1.6.





Aucun commentaire:

Enregistrer un commentaire