Reputation: 31724
Well I know it is a stupid question, but lets think on it for a second.
Why can't we have a repl mode or kind of a shell for Java. Say I just want to do Math.max(2,3)
to get output 3. It can be similar to Scala repl mode, where by default the class and main declarations are handled (it extends to App
) and only an expression is evaluated.
Technically:
javac
can be a bit modified for such casesIt would be cool to have a default shell for each JVM process, where on the run, one can access or set some say static variables and have live information.
All this would have been thought off, but why hasn't it been accepted by majority (there are some open source implementations though)
Upvotes: 3
Views: 637
Reputation: 33
You could try http://www.javarepl.com/ or console version from https://github.com/albertlatacz/java-repl
Upvotes: 1
Reputation: 11185
Like @Sean suggested you can indeed use bean shell in repl mode.
java -cp ./bsh-2.0b4.jar bsh.Interpreter
BeanShell 2.0b4 - by Pat Niemeyer ([email protected])
bsh % System.out.println("Hello World");
Hello World
Alternatively, the less known Display
tab on the eclipse IDE can execute arbitrary java code and evaluate expressions on the fly. Ctrl+U
runs the expression and Ctrl+Shift+I
evaluates them. It is not repl mode, but comes close.
Upvotes: 2
Reputation: 394
The Display view in Eclipse provides a lot of convenient behaviour in this area, with command completion, access to the running application stack, and console output through System.out.
Upvotes: 2