我正在使用反射来获取所有方法参数名称。
问题是当其中一个参数的类型为:the.package.myobject [] (array)
String name = method.getParameterTypes()[0].getName()
我得到:[the.package.myobject;]//字母 L 和符号 ;
如何获得纯类型名称? (没有子串)
最佳答案
您需要检查 type.isArray()
,如果是,则使用 getComponentType()
。
final Class<?> c = method.getParameterTypes()[0];
final String name = (c.isArray()? c.getComponentType() : c).getName();
关于java - Reflection Method.getParameterTypes() - 对象参数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13379560/