JShell is a command line interactive tool introduced in Java 9 version, allowing programmers to execute simple statements, expressions, variables, methods, classes , interface, etc.. No need to declare the main() method.
In JShell, the compiler warns the programmer about type conversion issues by throwing errors. However, if the programmer is aware of this, explicit conversion will be required. If we need to store a smaller data value into a larger type conversion, implicit conversion is required.
There are two kinds of integerType conversion:
<strong>C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> byte b = 128; | Error: | incompatible types: possible lossy conversion from int to byte | byte b = 128; | ^-^ jshell> short s = 123456; | Error: | incompatible types: possible lossy conversion from int to short | short s = 123456; | ^----^ jshell> short s1 = 3456 s1 ==> 3456 jshell> int i1 = 4567; i1 ==> 4567 jshell> s1 = i1; | Error: | incompatible types: possible lossy conversion from int to short | s1 = i1; | ^^ jshell> s1 = (short) i1; s1 ==> 4567 jshell> int num = s1; num ==> 4567</strong>
The above is the detailed content of How to implement integer type conversion in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!