How to call a private method from outside a java class

后端 未结 5 1369
北海茫月
北海茫月 2020-12-01 03:33

I have a Dummy class that has a private method called sayHello. I want to call sayHello from outside Dummy. I think it sh

5条回答
  •  春和景丽
    2020-12-01 04:32

    method = object.getClass().getDeclaredMethod(methodName);
    method.setAccessible(true);
    method.invoke(object);
    

提交回复
热议问题