Home >Java >javaTutorial >What are the different states of REPL in Java 9?
REPL stands for Read-Evaluate-Print-Loop. It saves some state, one for every statement in JShell. This state determines the execution status of code fragments and variables. It can be determined by the result of the eval() method of the JShell instance, which is used to evaluate the code.
Seven different states are listed below.
import java.util.List; import jdk.jshell.*; import jdk.jshell.Snippet.Status; public class JShellTest { public static void main(String args[]) { JShell shell = JShell.<strong>create()</strong>; <strong>List<SnippetEvent></strong> events = shell.<strong>eval</strong>("int a, b, sum; " + "a = 12; b = 11; sum = a + b; " + "System.out.println(sum);" ); for(<strong>SnippetEvent </strong>event : events) { Snippet snippet = <strong>event.snippet()</strong>; <strong>Snippet.Status</strong> snippetstatus = shell.<strong>status</strong>(snippet); if(snippetstatus == <strong>Status.VALID</strong>) { System.out.println("Successfully executed"); } } } }
<strong>Successfully executed Successfully executed Successfully executed </strong>
The above is the detailed content of What are the different states of REPL in Java 9?. For more information, please follow other related articles on the PHP Chinese website!