Computer >> 컴퓨터 >  >> 프로그래밍 >> Java

Java 9 JShell에서 상세(Verbose) 모드를 설정하는 방법

JShellJava 9에서 새롭게 도입된 REPL(Read-Eval-Print Loop) 도구입니다. 이 도구를 활용하면 명령줄 프롬프트에서 간단한 코드 조각(snippet)을 즉시 실행하고 그 결과를 바로 확인할 수 있습니다.

JShell에 산술 표현식이나 변수 등을 입력하면 기본적으로 생성된 변수의 타입 정보 없이 결과 값만 화면에 표시됩니다. 하지만 상세(verbose) 모드를 활성화하면 입력한 명령의 실행 과정과 함께 변수의 타입 등 더 많은 정보를 확인할 수 있습니다. 상세 모드를 사용하려면 다음 명령을 실행하기만 하면 됩니다.

/set feedback verbose

상세 모드 사용 예제

아래 예제에서는 상세 모드가 켜져 있어, 생성되는 변수의 타입까지 자세하게 출력되는 것을 확인할 수 있습니다.

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

jshell> /set feedback verbose
| Feedback mode: verbose

jshell> 5.0 * 8
$1 ==> 40.0
| created scratch variable $1 : double

jshell> String str = "TutorialsPoint";
str ==> "TutorialsPoint"
| created variable str : String

jshell> void test() {
...> System.out.println("Tutorix");
...> }
| created method test()

jshell> test()
Tutorix

jshell> String str1 = new String("Tutorix");
str1 ==> "Tutorix"
| created variable str1 : String

jshell> "TutorialsPoint" + "Tutorix" + 2019
$6 ==> "TutorialsPointTutorix2019"
| created scratch variable $6 : String

jshell> int test1() {
...> return 10;
...> }
| created method test1()

jshell> test1()
$8 ==> 10
| created scratch variable $8 : int