1

like for-loop

is there any solution to evalute code dynamicly?

eval also unsupport import keyword.

main[1] eval java.lang.Class.forName("java.util.stream.IntStream").getDeclaredMethods()
 java.lang.Class.forName("java.util.stream.IntStream").getDeclaredMethods() = instance of java.lang.reflect.Method[51] (id=767)

main[1] print java.util.stream.IntStream.range(0, 3)
 java.util.stream.IntStream.range(0, 3) = "java.util.stream.IntPipeline$Head@67b64c45"

main[1] eval java.util.stream.IntStream.range(0, 3).forEachOrdered(n -> { System.out.println(n); })
com.sun.tools.example.debug.expr.ParseException: Name unknown: n
 java.util.stream.IntStream.range(0, 3).forEachOrdered(n -> { System.out.println(n); }) = 空值

Java traditional for-loop also unsupported.

main[1]
main[1] eval  for (int i = 1; i <= 10; i++) {
            System.out.println(i);
无法识别的命令: 'system.out.println(i);'。请尝试获得帮助...
main[1]         }com.sun.tools.example.debug.expr.ParseException: Encountered " "for" "for "" at line 1, column 3.
Was expecting one of:
   

CS QGB
  • 297
  • 1
  • 3
  • 12

1 Answers1

0

in the jdb session, if you run help, then you might see something like this:

Initializing jdb ...
> help
** command list **
...

print <expr>              -- print value of expression
dump <expr>               -- print all object information
eval <expr>               -- evaluate expression (same as print)
...

and the description of eval says evaluate expression, so it's not evaluate statement which is what you really want, please correct me if i am wrong, thanks!

  • How to eval statement in jdb? – CS QGB Jan 25 '23 at 11:32
  • Hi @CSQGB, well, we know that a `statement` is a complete instruction, and in java, that means it consist of `expression` and a `semicolon`, and i think you can just write these code in a *.java file and compile it first with -g flag and then in `jdb session`, you can just set a break point at the line you wanna check out, after `run` then using `step` and `print` command to see what is going on at a specific point, and no offense, do you know how to use these jdb commands? – 張根源 Jan 25 '23 at 20:28