JShell 도구가 Java 9 에 도입되었습니다. 버전. REPL이라고도 합니다. (Read-Evaluate-Print-Loop) 도구를 사용하면 Java 코드를 실행하고 즉각적인 결과를 얻을 수 있습니다. class와 같이 선언된 유형을 나열해야 합니다. , 인터페이스 , 열거 등을 사용하여 "/types " 명령.
아래는 다양한 "/유형입니다. " JShell의 명령.
/types /types [ID] /types [Type_Name] /types -start /types -all
- /유형: 이 명령은 JShell에서 생성된 모든 활성 유형(클래스, 인터페이스, 열거형)을 나열합니다.
- /유형 [ID]: 이 명령은 ID [ID]에 해당하는 유형을 표시합니다. .
- /types [유형_이름]: 이 명령은 [Type_Name]에 해당하는 유형을 표시합니다. .
- /types -start: 이 명령을 사용하면 JShell 시작 스크립트에 추가된 유형을 나열할 수 있습니다.
- /types -all: 이 명령을 사용하면 현재 세션의 모든 유형을 나열할 수 있습니다(JShell 시작 시 활성, 비활성 및 로드됨).
아래 코드 스니펫에서는 클래스, 인터페이스 및 열거형 유형을 생성했습니다. 그런 다음 다른 "/types " 명령.
jshell> enum Operation {
...> ADDITION,
...> DIVISION;
...> }
| created enum Operation
jshell> class Employee {
...> String empName;
...> int age;
...> public void empData() {
...> System.out.println("Employee Name is: " + empName);
...> System.out.println("Employee Age is: " + age);
...> }
...> }
| created class Employee
jshell> interface TestInterface {
...> public void sum();
...> }
| created interface TestInterface
jshell> /types
| enum Operation
| class Employee
| interface TestInterface
jshell> /types 1
| enum Operation
jshell> /types -start
jshell> /drop Operation
| dropped enum Operation
jshell> /types -all
| enum Operation
| class Employee
| interface TestInterface