Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

result of invoke method

 
Nada Mohammed
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Junilu Lacar
Bartender
Pie
Posts: 7771
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic