- Java 9 Programming Blueprints
- Jason Lee
- 134字
- 2021-07-02 18:56:27
REPL
One change that seems to excite a lot of people isn't a language change at all. It's the addition of a REPL (Read-Eval-Print-Loop), a fancy term for a language shell. In fact, the command for this new tool is jshell. This tool allows us to type or paste in Java code and get immediate feedback. For example, if we wanted to experiment with the Streams API discussed in the preceding section, we could do something like this:
$ jshell | Welcome to JShell -- Version 9-ea | For an introduction type: /help intro jshell> List<String> names = Arrays.asList(new String[]{"Tom", "Bill", "Xavier", "Sarah", "Adam"}); names ==> [Tom, Bill, Xavier, Sarah, Adam] jshell> names.stream().sorted().forEach(System.out::println); Adam Bill Sarah Tom Xavier
This is a very welcome addition that should help Java developers rapidly prototype and test their ideas.