开发者

how to get method parameters name from java class? [closed]

开发者_Go百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

only parse java source file ?

or has other solutions?


found paranamer project can resolve this.

use case:

   Method method = Foo.class.getMethod(...);
   Paranamer paranamer = new CachingParanamer();
   String[] parameterNames = paranamer.lookupParameterNames(method) 

project home:http://paranamer.codehaus.org


Parsing javadocs is probably the best bet, assuming you have those.

If you don't, it's java source. if you don't have java source or javadocs, you're outta luck.


I'm not sure if I do understand you question... It would be easier to give an answer if your question was longer and would tell something about what you are trying to do.

Compiled class files may contain parameter names, but generally they don't, and for interfaces they never do. See my question Preserving parameter/argument names in compiled java classes and the numerous ansers for more information about it.


I believe you can get the information from an annotation parser in javac (apt in JDK5).

If you only have class files, then they would need to have debugging information included to include parameter names. Then I guess you could parse the class files with, say, ObjectWeb's ASM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜