有没有类似 Python 的 Java 交互式控制台?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/787313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any Python-like interactive console for Java?
提问by e-satis
I spent a lot of time programming in Java recently, and one thing I miss from scripting languages was the ability to test them in a console.
我最近花了很多时间用 Java 编程,而我对脚本语言怀念的一件事是在控制台中测试它们的能力。
To quickly test a java program, I have to edit a file, then turn it to bytecode and execute it. Even using an IDE, it loses its fun after the 372 th time.
为了快速测试 Java 程序,我必须编辑一个文件,然后将其转换为字节码并执行它。即使使用IDE,在第372次之后就失去了乐趣。
I would like to know if there is a product out there that features anything like an interactive console (I bet you need a JIT compiler) and some autocompletion (with relexivity, I suppose it's possible).
我想知道是否有一款产品具有交互式控制台之类的功能(我打赌您需要一个 JIT 编译器)和一些自动完成功能(具有相关性,我想这是可能的)。
Maybe that's something very common that I just don't know about or something completely impossible, but its worst asking :-)
也许这是我不知道的非常普遍的事情或完全不可能的事情,但这是最糟糕的要求:-)
采纳答案by Charlie Martin
Yes; jshell, and before that some close approximations are Groovy, Clojure, Scala, and the Bean Shell.
是的; jshell,在此之前的一些近似值是Groovy、Clojure、Scala和Bean Shell。
回答by Sniggerfardimungus
I've occasionally run into the same problem and have a partial solution. I keep around a file (as Charlie Martin said, Java needs its class contexts) that is little more than a test program. In a second window - a console - I have a script that I run that just checks the modification time of the source file every second or two. When it sees the source change, it re-compiles it (I'm usually fiddling in C, but I've done this with Java, as well) and executes the result.
我偶尔会遇到同样的问题,并有部分解决方案。我保存了一个文件(正如 Charlie Martin 所说,Java 需要它的类上下文),它只不过是一个测试程序。在第二个窗口 - 一个控制台 - 我有一个我运行的脚本,它每隔一两秒检查一次源文件的修改时间。当它看到源代码更改时,它会重新编译它(我通常在 C 中摆弄,但我也用 Java 完成了这一点)并执行结果。
It's not a great solution, but its a fast one-off and I've found it to be very useful.
这不是一个很好的解决方案,但它是一种快速的一次性解决方案,我发现它非常有用。
回答by laz
An approach that I have used to some degree of success is to debug in Eclipse and use the display view. What the display view gives you is the ability to manipulate the code currently running in the JVM through executing Java statements. Any object available at the particular break point you are stopped at is in scope within the display view. While this isn't exactly what you are looking for it does provide some of the features that a REPL provides for other programming environments. See Debugging with the Eclipse Platformfor more information.
我在某种程度上成功使用的方法是在 Eclipse 中调试并使用显示视图。显示视图为您提供的是通过执行 Java 语句来操作当前在 JVM 中运行的代码的能力。在您停止的特定断点处可用的任何对象都在显示视图的范围内。虽然这不是您正在寻找的内容,但它确实提供了 REPL 为其他编程环境提供的一些功能。有关更多信息,请参阅使用 Eclipse 平台进行调试。
回答by Brian Agnew
回答by stepancheg
You can execute Scala interactive interpreter too.
您也可以执行 Scala 交互式解释器。
回答by Anders
Jgrasp IDE have a interactive console where you can test in, i use it a lot, and there is alos a debug view showing variabel etc efter you have deklare them.
Jgrasp IDE 有一个交互式控制台,您可以在其中进行测试,我经常使用它,并且在您删除它们之后,还有一个显示变量等的调试视图。
It is opensoruce and you can get a copy att http://www.jgrasp.org/
它是 opensoruce,您可以在http://www.jgrasp.org/获取副本
// Anders
// 安德斯
回答by neu242
You can use BeanShellto run arbitrary Java code. If you want Eclipse integration, EclipseShellhas BeanShell support.
您可以使用BeanShell来运行任意 Java 代码。如果您想要 Eclipse 集成, EclipseShell有 BeanShell 支持。
回答by David Portabella
Java REPL http://www.javarepl.com/term.html
Java REPL http://www.javarepl.com/term.html
with an intellij plugin: http://plugins.jetbrains.com/plugin/7215?pr=
使用 Intellij 插件:http://plugins.jetbrains.com/plugin/7215?pr=