Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why no Repl mode for Java

Tags:

java

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:

  1. There is an interpreter running behind can execute it - If scala and groovy can, then that means the JVM is not the major issue
  2. If javac is the reason, say we remove all optimizations and it directly converts line by line strictly to java byte code, then there should be a way out. Type Inference might not be strong to show a lot of information, but atleast the output of methods can be shown. Probably javac can be a bit modified for such cases
  3. Ex: In the debugger, we attach break points to the line and then execute forward. A similar strategy can be applied

It 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)

like image 732
Jatin Avatar asked Dec 22 '25 10:12

Jatin


2 Answers

This is more or less exactly what BeanShell does.

like image 121
Sean Owen Avatar answered Dec 24 '25 01:12

Sean Owen


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.

like image 20
jc1001 Avatar answered Dec 24 '25 01:12

jc1001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!