java反射如何实现?
我想返回一个包含安卓资源的所有公共方法的列表,如methodname+参数,例如相机的open(int cameraId)、release()、setDisplayOrientation(int degrees)等等。 所以我创造了这个方法
public List<String> getPublicMethods(String api) throws ClassNotFoundException {
Class clazz = Class.forName("安卓.hardware.Camera");
Method[] publicMethods= clazz.getDeclaredMethods();
List<String> list=new ArrayList<>();
for (Method met : publicMethods)
list.add(met.getName());
return list;
}
我只能返回一个列表。如何更改它,使其也返回参数
# 1 楼答案
考虑返回一个哈希表。这将使您能够灵活地返回这两个对象。方法名将用作键,然后参数将用作列表。差不多
方法名的字符串 参数列表的列表