Home Java javaTutorial What are the different feedback modes for JShell in Java 9?

What are the different feedback modes for JShell in Java 9?

Sep 06, 2023 am 10:25 AM

Java 9中的JShell有哪些不同的反馈模式?

JShell工具中执行操作时,会在return中显示一条消息(命令成功、错误、操作类型)创建的变量及其值)。它已使用以下命令进行自定义: “/set Feedback”。此命令显示当前配置的返回类型以及可用的不同返回模式

1

2

3

4

5

6

7

8

<strong>jshell> /set feedback

| /set feedback normal

|

| Available feedback modes:

| concise

| normal

| silent

| verbose</strong>

Copy after login

JShell 中有四种反馈模式,如下所示:

1) /set反馈正常:这是默认JShell 反馈。当我们计算表达式时,JShell 返回相应的结果以及存储该值的内部变量。在变量创建的情况下,JShell 返回变量的名称和相应的值。创建数据类型(方法或类)时,JShell 会发送一个返回值,指定我们创建的类型。

1

2

3

4

5

6

7

8

9

10

11

12

13

<strong>jshell> /set feedback normal

| Feedback mode: normal

 

jshell> 5 + 5

$1 ==> 10

 

jshell> int i = 20

i ==> 20

 

jshell> int sum(int a, int b) {

...> return a + b;

...> }

| created method sum(int,int)</strong>

Copy after login

2) /set feedback verbose: 这是最具有信息性的反馈模式。在评估指令时,它会显示相应的结果,以及被赋值的内部变量和表达式的类型。对于变量的创建也是如此。至于数据类型的创建,返回结果与正常模式相同。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<strong>jshell> /set feedback verbose

| Feedback mode: verbose

 

jshell> 2 + 2

$1 ==> 4

| created scratch variable $1 : int

 

jshell> String str = "Tutorix"

str ==> "Tutorix"

| created variable str : String

 

jshell> int div(int a, int b) {

...> return a/b;

...> }

| created method div(int,int)</strong>

Copy after login

3) /set feedback concise: 这种模式显示最小的信息量。在评估表达式时,它告诉我们创建的内部变量的名称以及表达式的结果。另一方面,关于数据类型(变量、方法或类)的创建,JShell 不会返回任何结果(除非代码有错误)。

1

2

3

4

5

6

7

8

9

<strong>jshell> /set feedback concise

jshell> 2 + 2

$1 ==> 4

jshell> int i = 10;

jshell> float y = "xyz";

| Error:

| incompatible types: java.lang.String cannot be converted to float

| float y = "xyz";

| ^---^</strong>

Copy after login

4) /set feedback silent: 这种模式不显示任何信息。当我们输入一个表达式进行求值时,JShell会将结果存储在一个内部变量中,但不会在屏幕上显示相应的结果。对于数据类型(变量、方法或类)的创建也是如此。所有的操作都在内部完成,不会在屏幕上显示任何结果(除非出现错误)

1

2

3

4

5

6

7

8

9

10

11

12

<strong>jshell> /set feedback silent

-> 3+3

-> int x = 7

-> int sum(int x, int y) {

>> return x + y;

>> }

-> double y = "abc";

| Error:

| incompatible types: java.lang.String cannot be converted to double

| double y = "abc";

| ^---^

-></strong>

Copy after login

The above is the detailed content of What are the different feedback modes for JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Java's classloading mechanism work, including different classloaders and their delegation models? How does Java's classloading mechanism work, including different classloaders and their delegation models? Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache? How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache? Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading? How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading? Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution? How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution? Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management? How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management? Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

See all articles