Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java8で実行時にメソッドの引数の名前がとれるかんじ。 http://openjdk.java.net/jeps/118 とか。 http://download.java.net/jdk8/docs/api/java/lang/reflect/Parameter.html#getName() とか。
import java.lang.reflect.Method;
import java.util.Arrays;
public class ParameterNameExample {
public static void main(String... args) {
Class<ParameterNameExample> clz = ParameterNameExample.class;
Arrays.stream(clz.getMethods()).filter(m -> m.getName().startsWith("method"))
.map(m -> m.getName() + Arrays.toString(m.getParameters()))
.forEach(System.out::println);
}
public void method1(String hoge) {
}
public void method2(Object fuga, Object piyo) {
}
}
$ java8c ParameterNameExample.java
$ java8 ParameterNameExample
method1[ java.lang.String arg0]
method2[ java.lang.Object arg0, java.lang.Object arg1]
$ java8c -parameters ParameterNameExample.java
$ java8 ParameterNameExample
method2[ java.lang.Object fuga, java.lang.Object piyo]
method1[ java.lang.String hoge]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.