Java开发之反射的使用

通过类名获取类。

Class serviceManager = Class.forName("android.os.ServiceManager");

获取方法

Method method = serviceManager.getMethod("getService", String.class);

调用方法

method.invoke(serviceManager.newInstance(), "phone");

参考博客:

http://blog.csdn.net/njchenyi/article/details/1620939

http://www.blogjava.net/zh-weir/archive/2011/03/26/347063.html

原文地址:https://www.cnblogs.com/liyiran/p/5296790.html