mercredi 26 août 2015

Accessing inner hidden abstract class to get status updates

I want to invoke a private method which takes abstract class parameter and that abstract class is hidden (I can not access it directly). I need to get the updates whenever methods of abstract class are invoked by some other class.

Class I am refereeing to is:

public class A{

  private void method(AbstractClassA object){ ... }

 // please note below class is hidden. I can not do A.AbstractClassA . I have to access it using reflection unless there is any other way

  public abstract class AbstractClassA {

  //I am interested in getting this int whenever someone else calls the progressUpdate

       public void progressUpdate(int update);
   }
}

I am trying to access like this:

public class myClass{

    Class<?> abstractClass =  Class.forName("<package>.A$AbstractClassA");
    A a = new A();
    Method someMethod = a.getDeclaredMethod("method", (Class[])null);
    someMethod.setAccessible(true);
    someMethod.invoke(a, <something which I don't know>); //how to pass paramerts here so that I get all callbacks whenever progressUpdate is called by someone else and "update" parameter is changed.


}





Aucun commentaire:

Enregistrer un commentaire