jshell|Welco"/> jshell|Welco">

Home  >  Article  >  Java  >  How do we avoid compilation errors in JShell in Java 9?

How do we avoid compilation errors in JShell in Java 9?

WBOY
WBOYforward
2023-08-28 14:57:021025browse

在Java 9的JShell中,我们如何避免编译错误?

JShell is an interactive tool that enables us to execute java code and display the output immediately. JShell is a REPL (read-evaluate-print-loop) tool run from the command line prompt. If we need to avoid compile errors in JShell, then we must declare these variables before using it. Error messages in JShell can use the symbols "^--^" to highlight errors.

In the following code snippet, an int variable is declared "div" Try using variables that have not been declared yet: num1 and num2, So JShell reports compilation errors indicating that the compiler cannot find these variables.

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

jshell> int div = num1 / num2
|  Error:
|  cannot find symbol
|  symbol: variable num1
|  int div = num1 / num2;
|  ^--^
|  Error:
|  cannot find symbol
|  symbol: variable num2
|  int div = num1 / num2;
|  ^--^</strong>

In the following code snippet, JShell displays the names of the variables: num1 and num2 , followed by two equal signs and a greater than sign (= = >).

<strong>jshell> int num1 = 35
num1 ==> 35

jshell> int num2 = 7
num2 ==> 7

jshell> int div = num1 / num2
div ==> 5</strong>

The above is the detailed content of How do we avoid compilation errors in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete