Meaningless Drivel is fun!
The moose likes Java in General and the fly likes result of invoke method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "result of invoke method " Watch "result of invoke method " New topic

result of invoke method

Nada Mohammed
Ranch Hand

Joined: Sep 22, 2000
Posts: 30
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
is there is any way to casting result of invoke dynamically
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

Joined: Feb 26, 2001
Posts: 6529

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.

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: result of invoke method
It's not a secret anymore!