File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reflection & primitive method parameters

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surprisingly it works when I call the invoke method
with an Integer[] as the 2nd parameter.

Yahoo!
Pho
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic