如何在Android中列出实现特定界面的所有类?

时间:2017-03-16 11:35:25

标签: java android reflection

在Java(NetBeans)中,我意识到它......

ClassPathLoader pathLoader = new ClassPathLoader(".");
try {
//get Classes
Hashtable ht = pathLoader.getClasses();
Set s = ht.keySet();
Iterator iter = s.iterator();
String fullName = null;
    while(iter.hasNext()) {
        try {
        fullName = (String) iter.next();
        //create class
        Class cls = Class.forName(fullName);
        //get interface from the class
        Class[] interfaces = cls.getInterfaces();
        for(int i = 0; i < interfaces.length; i++) {
        if(interfaces[i].getName().equals("IMyObserver.IFeature")) {

        //Field field = cls.getDeclaredField("LOCATION");
        //String location = (String)field.get(null);
        Constructor cons2 = cls.getDeclaredConstructor(List.class);

        Object oo = cons2.newInstance(qList);

        System.out.println(fullName);
        }
    }

这非常有效,但在Android中它不起作用。我认为问题出在ClassPath上。有没有人有想法?

0 个答案:

没有答案