> Java > java지도 시간 > 본문

Java 9의 JShell에서 ID별로 코드 조각을 어떻게 실행할 수 있나요?

WBOY
풀어 주다: 2023-08-30 22:17:02
앞으로
1325명이 탐색했습니다.

在Java 9的JShell中,我们如何通过ID执行代码片段?

JShell is an interactive tool (REPL) introduced in Java 9. We can execute snippets like expressions, variables, methods, classes, and etc without a main () method in the JShell tool.

We can execute any prior snippet by simply typing /id, which indicates the snippet’s ID. For instance, if we type "/1", then JShell can display the first snippet that we have entered, executes it, and shows the result. We can re-execute the last snippet that we have entered (whether it is valid or invalid) by using "/!".

In the below code snippet, we have created a set of snippets, and execute those snippets by using /1, /2, /3, and /4.

<strong>C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> 2+10
$1 ==> 12

jshell> String s = "Tutorialspoint"
s ==> "Tutorialspoint"

jshell> System.out.println("Tutorialspoint")
Tutorialspoint

jshell> int num1 = 25
num1 ==> 25

jshell> /1
2+10
$5 ==> 12

jshell> /2
String s = "Tutorialspoint";
s ==> "Tutorialspoint"

jshell> /3
System.out.println("Tutorialspoint")
Tutorialspoint

jshell> /4
int num1 = 25;
num1 ==> 25</strong>
로그인 후 복사

在下面的代码段中,我们可以使用"/!"命令重新执行上一个代码段。

<strong>jshell> 2+5
$1 ==> 7

jshell> 10-6
$2 ==> 4

jshell> /1
2+5
$3 ==> 7

jshell> /!
2+5
$4 ==> 7</strong>
로그인 후 복사

위 내용은 Java 9의 JShell에서 ID별로 코드 조각을 어떻게 실행할 수 있나요?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!