• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reflection & primitive method parameters

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In trying to invoke a method via reflection; I discovered
that it's not possible to invoke a method that accepts
primitive parameters.

Method.invoke() accepts two params:
Object & Object[]
so the Method object returned will always match the 2nd burp().
Please confirm!
Thanks
Pho
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Been a while but I think it should be possible.
Why not do it the other way around:
use reflection to get a list of the Method objects, then look at each Method and find out it getParameterTypes? You'll get two methods, you can get the array of classes they accept then you should be able to reverse engineer your own answer...
If you do get a solution, post some code for us all to see how to do it...
(if this doesn't work, it may allow you to get a particular 'instance' of a mthod so you can explicitly call that one)
Dave.
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,
I finally found out a way to get hold of the method with
the primitive param.

To get a reference to the first burp() method,

The trick is that Integer.TYPE is of type Class which
represents primitive variables.
However this doesn't solve my problem, as I still can't
Method.invoke( .. );
Pho
[This message has been edited by Pho Tek (edited August 15, 2001).]
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surprisingly it works when I call the invoke method
with an Integer[] as the 2nd parameter.

Yahoo!
Pho
 
reply
    Bookmark Topic Watch Topic
  • New Topic