package com.supermap.testdemo;
import android.util.Log;
/**
* Created by Administrator on 2017/6/12 0012.
*/
public class Test {
private void log() {
Log.w("bruce", "hello world");
}
private void log(String content) {
Log.w("bruce", content);
}
}
try {
Method method = Test.class.getDeclaredMethod("log");
method.setAccessible(true);
method.invoke(new Test());
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Test test = new Test();
try {
Method method = test.getClass().getDeclaredMethod("log", String.class);
method.setAccessible(true);
method.invoke(test, "hello superMap");
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
最后
以上就是背后期待最近收集整理的关于通过反射调用private方法的全部内容,更多相关通过反射调用private方法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复