• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

result of invoke method

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 16630
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic