Hello every body i now that invoke method return Object type then we must cast this object to its original type .In my example method_1 can has any return type rimitive or object class a { Object method_1() { Object result = null ; try { result = m.invoke(methodName,new Object[] {}) ;} catch (Exception e) {} return result ; } is there is away to get return value from invoke method without casting or is there is any way to casting result of invoke dynamically or is there is any to go through method methodName and now what is its return value dynamically pleeease i need support Thanks a lot
nada, Refer to the JavaDocs forjava.lang.reflect.Method The methods you are looking for is getReturnType() To see if a Class represents a primitive type, you would invoke the Class.isPrimitive() method (go figure ) The invoke() method will only return type Object. You will definitely have to cast the result if you want to be able to use the object returned without resorting to more reflection. HTH, Junilu