2

This is the code which I am trying out:

JavaCompiler compilerA = ToolProvider.getSystemJavaCompiler();
int resultA = compilerA.run(null,null,null,"/Users/a/Documents/Java/a.java");
System.out.println("Compile result code = " + resultA);
File fileA = new File("/Users/a/Documents/Java/a.class");

JavaCompiler compilerB = ToolProvider.getSystemJavaCompiler();
int resultB = compilerB.run(null,null,null,"/Users/a/Documents/Java/b.java");
System.out.println("Compile result code = " + resultB);
File fileB = new File("/Users/a/Documents/Java/b.class");

Here I am compiling a Java class and then using reflection to get all the function names, parameters and return types. However, I have no clue how to get the names and return types of the local variables of the functions. I tried looking up bytecode outline but it says it isn't available for netbeans. Please help me out.

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
Blood Sport
  • 125
  • 1
  • 2
  • 12
  • 1
    You can't get the names of local variables with Java reflection. See http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable – rgerganov Jul 02 '12 at 05:13
  • I know i cant get them using Java reflection. But cant I get them using some other way? – Blood Sport Jul 02 '12 at 05:31

1 Answers1

2

Look at the javac compiler options. Especially -g:vars.

This fills the local variable table for debuggers.

See same qustion Java Reflection: How to get the name of a variable?

Community
  • 1
  • 1
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138