當我檢查使用java反射的類中的方法的參數java.math.BigDecimal
和java.lang.String
isPrimitive()
返回false。是的,他們不是原始的,但i want to differnciate between user defined class and these java class
Java - BigDecimal和Reflection
Class[] parameterTypes = method2.getParameterTypes();
for (Class class1 : parameterTypes) { // check the parameter type and put them in to a ArrayList
methodParams = new MethodParams();
strClassNameToFix = class1.getName();
strClassname =strClassNameToFix.replaceAll("\\[L", "").replaceAll("\\;","");
methodParams.setDataType(strClassname);
if(class1.isArray()){
methodParams.setArray(true);
}
if(class1.isPrimitive()){
methodParams.setPrimitive(true);
}
tempParamsList.add(methodParams);
}
基於上面的代碼我設置的假methodParams.setPrimitive(true);
真的,我已經這樣做了,因爲只有少數情況下,我得到的用戶定義的對象,在我的情況com.hexgen.ro.request.CreateOrderRO
所以如何設置?
也使用反射我得到的類的名字,它聲明的方法和參數的鍵入方法。
,但我沒能獲得參數名稱一樣,如果我已經宣佈類似下面的方法:
class test{
public String testMethod(int a, String b){
return "test";
}
}
在上面的代碼中,我能夠得到folloing
Class name : test
Method name : testMethod
Arguments Type : int and String
但i also want to get int a and String b
的參數類型,以及聲明的變量名
如何做到這一點。
請幫我完成這件事。
問候
我不相信Java字節碼保留方法參數的**名稱**。 – 2013-04-26 05:26:59
不錯,比它的意思是說這是不可能的吧? – 2013-04-26 05:28:52
請參閱http://stackoverflow.com/questions/2237803/can-i-obtain-method-parameter-name-using-java-reflection – 2013-04-26 05:31:04