• Post Reply Bookmark Topic Watch Topic
  • New Topic

get parameter name  RSS feed

 
Leo Campos
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

Somebody may tell me how can I get method parameter-name using reflection or others?



thank you.
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can get the name. The parameter name doesn't have any relevance outside the method so it wouldn't make sense to make it accessible.
 
Leo Campos
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building an application that use reflection to test several methods, and I need the parameter name of methods to show to system users.

it's important a lot.
:roll:

thanks.
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection is a low-level view that is not appropriate for humans. you should look into using the JavaBeans API to write your test classes. Basically you write a companion class, called a BeanInfo class, to describe your bean (java class). The java.beans package has the classes you'd use to get the information you require, for example, ParameterDescriptor which describes a method parameter. There's a ton of tutorials on the Java site that will help you get started.
 
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 Leo Campos:

it's important a lot.


Reflection alone isn't going to get you this information. You'll need to use something like Apache BCEL to probe the class file itself, looking in the debug information tables where these names are stored -- and then only if the classes are compiled with this information included.
 
Leo Campos
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!