Home > Java > javaTutorial > body text

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

WBOY
Release: 2023-08-28 14:57:02
forward
970 people have browsed it

在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>
Copy after login

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>
Copy after login

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!

source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!