/debug|Debuggingonjshell>5+3Penyusun:5"/> /debug|Debuggingonjshell>5+3Penyusun:5">

Rumah >Java >javaTutorial >Bagaimana untuk menyahpepijat JShell dalam Java 9?

Bagaimana untuk menyahpepijat JShell dalam Java 9?

WBOY
WBOYke hadapan
2023-08-26 08:41:131017semak imbas

如何在Java 9中调试JShell?

JShell 是一种 REPL 工具,允许运行代码片段,而无需将它们放入类中。此工具提供了一种在 Java 中评估声明语句表达式的方法,无需创建 main() strong> 方法来测试代码的某些部分。

命令"/debug"可用于显示调试信息 JShell工具实现。一旦我们输入“/debug”命令,调试模式就会开启。启用调试模式并输入诸如简单加法或简单字符串之类的内容后,它将打印如下。

Example-1

<strong>jshell> /debug
| Debugging on</strong>

<strong>jshell> 5+3
Compiling: 5+3
Kind: EXPRESSION_STATEMENT -- 5 + 3;
compileAndLoad [Unit($1)]
++setCompilationInfo() Snippet:VariableKey($1)#11-5+3
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.*;class $JShell
$11 {
public static
int $1;
public static Object do_it$() throws Throwable {
return $1 = 5+3;
}
}

-- diags: []
setStatus() Snippet:VariableKey($1)#11-5+3 - status: VALID
compileAndLoad ins = [Unit($1)] -- legit = [Unit($1)]
Compiler generating class REPL.$JShell$11
compileAndLoad [Unit($1)] -- deps: [] success: true
recordCompilation: Snippet:VariableKey($1)#11-5+3 -- status VALID, unresolved []

$1 ==> 8</strong>

示例 2

<strong>jshell> /debug
| Debugging on

jshell> 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: VALID
compileAndLoad ins = [Unit(s)] -- legit = [Unit(s)]
Compiler generating class REPL.$JShell$12
compileAndLoad [Unit(s)] -- deps: [] success: true
recordCompilation: Snippet:VariableKey(s)#12-String s = "Adithya"; -- status VALID, unresolved []
s ==> "Adithya"</strong>

如果我们想要“关闭”调试模式,请再次键入” /debug”同一会话的命令。

<strong>jshell> /debug
| Debugging off</strong>

Atas ialah kandungan terperinci Bagaimana untuk menyahpepijat JShell dalam Java 9?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:tutorialspoint.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam