Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Reflections Overloaded Methods

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Knows anybody a example of Reflections invoke method with Overloaded Methods?
Example:
class x{
public void a(){...}
public void a(String a){...}
public void a(String a, int b){...}
public void a(int a){...}
}
Thanks
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second pararmeter of the invoke method of Method takes an array that contains the parameters of the method.
Of course that assumes that the input parameters are all Objects. I have never tried it with mixing in primitives.
hmmmm. . . have to think about that for a bit.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there are primitives you use the type constants Integer.TYPE, Float.TYPE, etc., which are Class objects that represent primitive types.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use reflection getMethod() to get the Method object, you give an array of classes that match the parameters. So if a method name is overloaded with several different sets of parameters, you specify which set of parameters you want and you get the right Method object. Here's a little helper I use:

See how it uses the array of classes to specify the parameters? Pretty cool.
Hope that helps!
[ August 05, 2003: Message edited by: Cindy Glass ]
 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Thanks by response, i will see all tips .
Bye.
reply
    Bookmark Topic Watch Topic
  • New Topic