aspose file tools*
The moose likes Beginning Java and the fly likes Reflection & primitive method parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reflection & primitive method parameters" Watch "Reflection & primitive method parameters" New topic
Author

Reflection & primitive method parameters

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

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


Regards,

Pho
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Nov 05, 2000
Posts: 761

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

Joined: Nov 05, 2000
Posts: 761

Surprisingly it works when I call the invoke method
with an Integer[] as the 2nd parameter.

Yahoo!
Pho
 
 
subject: Reflection & primitive method parameters