lundi 13 janvier 2020

Reflective class call succeeds on newInstance(), fails on getMethod()

The following code is in an Android application I am working on. I have loaded the class in question using SplitInstallManager to load a Dynamic Feature Module.

I have a public class with a public method

public class Example {

    public Example(){
    //do something
         Log.i("Hello", "World");
    }
    public void testMethod()
    {
         Log.i("Test", "Method");
    }
}

in another class of my base application code, I can call:

Class c = Class.forName("my.example.package.Example");
c.newInstance(); //This prints the Hello World log line
Method m = c.getMethod("testMethod"); //this line fails with NoSuchMethodException

How is it possible this is happening?





Aucun commentaire:

Enregistrer un commentaire