File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
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

Joined: Feb 26, 2001
Posts: 5019
    
    8

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

Junilu - [How to Ask Questions] [How to Answer Questions]
 
 
subject: result of invoke method