您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何在Java 9中调试JShell?

2024/3/3 3:45:29发布42次查看
jshell 是一种 repl 工具,允许运行代码片段,而无需将它们放入类中。此工具提供了一种在 java 中评估声明、语句和表达式的方法,无需创建 main() strong> 方法来测试代码的某些部分。
命令/debug可用于显示调试信息 jshell工具实现。一旦我们输入“/debug”命令,调试模式就会开启。启用调试模式并输入诸如简单加法或简单字符串之类的内容后,它将打印如下。
example-1jshell> /debug| debugging onjshell> 5+3compiling: 5+3kind: expression_statement -- 5 + 3;compileandload [unit($1)]++setcompilationinfo() snippet:variablekey($1)#11-5+3package repl;import java.io.*;import java.math.*;import java.net.*;import java.nio.file.*;import java.util.*;import java.util.concurrent.*;import java.util.function.*;import java.util.prefs.*;import java.util.regex.*;import java.util.stream.*;class $jshell$11 {public staticint $1;public static object do_it$() throws throwable {return $1 = 5+3;}}-- diags: []setstatus() snippet:variablekey($1)#11-5+3 - status: validcompileandload ins = [unit($1)] -- legit = [unit($1)]compiler generating class repl.$jshell$11compileandload [unit($1)] -- deps: [] success: truerecordcompilation: snippet:variablekey($1)#11-5+3 -- status valid, unresolved []$1 ==> 8
示例 2jshell> /debug| debugging onjshell> string s = "adithya"compiling: string s = "adithya";kind: variable -- string s = "adithya"compileandload [unit(s)]++setcompilationinfo() snippet:variablekey(s)#12-string s = "adithya";package repl;import java.io.*;import java.math.*;import java.net.*;import java.nio.file.*;import java.util.*;import java.util.concurrent.*;import java.util.function.*;import java.util.prefs.*;import java.util.regex.*;import java.util.stream.*;import static repl.$jshell$11.$1;class $jshell$12 {public static string s;public static object do_it$() throws throwable {string s_ ="adithya";return s = s_;}}-- diags: []setstatus() snippet:variablekey(s)#12-string s = "adithya"; - status: validcompileandload ins = [unit(s)] -- legit = [unit(s)]compiler generating class repl.$jshell$12compileandload [unit(s)] -- deps: [] success: truerecordcompilation: snippet:variablekey(s)#12-string s = "adithya"; -- status valid, unresolved []s ==> "adithya"
如果我们想要“关闭”调试模式,请再次键入” /debug”同一会话的命令。
jshell> /debug| debugging off
以上就是如何在java 9中调试jshell?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product