Is there something like python's interactive REPL mode, but for Java?

前端 未结 28 1021
一个人的身影
一个人的身影 2020-11-29 16:38

Is there something like python\'s interactive REPL mode, but for Java? So that I can, for example, type InetAddress.getAllByName( localHostName ) in a window, a

相关标签:
28条回答
  • 2020-11-29 16:57

    edit Since Java 9 there's JShell

    Original answer follows

    You can also use Groovy Console. It is an interactive console where you can do what you want. Since Groovy also includes classes from the core java platform, you'll be able to use those classes as well.

    It looks like this:

    Screenshot of Groovy

    0 讨论(0)
  • 2020-11-29 16:57

    Jython is a python implementation which lets you inspect and interact with Java objects.

    >>> from java.net import *
    >>> InetAddress.getAllByName("google.com")
    array(java.net.InetAddress,[google.com/209.85.171.100, 
                                google.com/74.125.45.100,
                                google.com/74.125.67.100])
    
    0 讨论(0)
  • 2020-11-29 16:57

    Jython, JIRB for JRuby, Groovy (groovyconsole et al) and Beanshell are all viable options.

    I've used the InteractiveConsole for Jython, it really worked nicely in the app.

    0 讨论(0)
  • 2020-11-29 16:58

    As an alternative to Groovy, try Beanshell: http://www.beanshell.org/

    It is more Java-like and allows you to use Java-syntax directly.

    0 讨论(0)
  • 2020-11-29 16:59

    Most IDE's have a window called something like "immediate mode" that will allow you to evaluate java code on the fly.

    0 讨论(0)
  • 2020-11-29 16:59

    For java 8, there is nudge4j. see https://github.com/lorenzoongithub/nudge4j

    ... and the beauty is that you can pilot your application from the browsert

    0 讨论(0)
提交回复
热议问题