lundi 13 juillet 2015

Eclipse Compiler Equivalent of -parameters

I would like to use the Java Reflection API to obtain the names method parameters, using java.lang.reflect.Parameter.getName().

I can achieve this for code that has been compiled using Sun's javac compiler, if I specify the -parameters flag, as seen here:

$> javac 
Usage: javac <options> <source files>
where possible options include:
  ...
  -parameters                Generate metadata for reflection on method parameters
  ...

However, I cannot find any matching option in eclipse that will add these names to the compiled byte-code.

Therefore, in Eclipse the parameter names are substituted with arg0, arg1, ...

The following illustrates the problem, stated output is from debug/run in Eclipse:

public class Example {
    public static void main(String[] theseAreMyCliArgs) {
        // Ouptut [java.lang.String[] arg1]
        // Should yield [java.lang.String[] theseAreMyCliArgs]
        System.out.println(Arrays.toString(Example.class.getMethods()[0].getParameters()));
    }
}





Aucun commentaire:

Enregistrer un commentaire