The central class in the API is the jdk.jshell.JShell class. This class is the evaluation state engine, whose state is modified with every evaluation of the snippet. As we saw earlier, the snippets are evaluated using the eval(String snippet) method. We can even drop the previously evaluated snippet using the drop(Snippet snippet) method. Both these methods result in a change of the internal state maintained by jdk.jshell.JShell.
The code snippets passed to the JShell evaluation engine are categorized as follows:
- Erroneous: Syntactically incorrect input
- Expressions: An input which might or might not result in some output
- Import: An import statement
- Method: A method declaration
- Statement: A statement
- Type declaration: A type, ...