• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get method arguments names with reflection  RSS feed

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
im trying to find some way to get method args names with reflection or any other way
for example if I have method :

public String getName( String myName , int iAge)

I will like to get the arguments names "myName" and "iAge"
but all I found I can get only the arguments types .
is there any way to do that ?
Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't get them via reflection, but they may be available from the "LocalVariableTable" attribute of a method in the class file. A class file parsing library like BCEL would be needed to get at these. Not all classes or all methods will have this table.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that information also available in the Doclet produces by the Javadoc tool?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Garrett Rowe:
Isn't that information also available in the Doclet produces by the Javadoc tool?


Yes, but Javadoc operates on the source code. If you have the source code, you can look at it, of course
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hmmm, yes. Well, now that we've returned from that unscheduled commercial break, note that none of these documents will be of any help, since the parameter names are not available via reflection.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:


Hmmm, yes. Well, now that we've returned from that unscheduled commercial break, note that none of these documents will be of any help, since the parameter names are not available via reflection.


You are the King of subtle backhands.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
So the conclusion is?
bcal or what
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello again
well I try to use bcel , tried to run simple example with no lock
here is what I have :





the clazz is null , why ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Meir Yan:

the clazz is null , why ?


Try printing MyTestCls.class.toString() to System.out -- the answer should be obvious. Try class.getName() instead.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still i can't make it work ..
say some one told me some thing about annotations
can this help me here ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!