JShell
Jump to navigation
Jump to search
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
|
JShell is a Java read-eval-print loop which was first introduced in the JDK 9.[1] It is tracked by JEP 222 jshell: The Java Shell (Read-Eval-Print Loop).[2] One reason why JShell was proposed for Java 9 is the lack of a standard interactive environment for the language; the de facto library to use a Java REPL was often BeanShell, which has been dormant since 2003, and arbitrarily diverged from the Java language.[3][4]
Example
[edit | edit source]jshell> int a[] = { 0, 1, 3, 5, 8 }
a ==> int[5] { 0, 1, 3, 5, 8 }
jshell> int fact(int n) {
...> return n < 2 ? 1 : n * fact(n - 1);
...> }
| created method fact(int)
jshell> for (int i = 0; i < a.length; ++i)
...> a[i] = fact(a[i]);
jshell> a
a ==> int[5] { 1, 1, 6, 120, 40320 }
See also
[edit | edit source]References
[edit | edit source]- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).