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

前端 未结 28 1171
一个人的身影
一个人的身影 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 17:10

    For folks with access to Mathematica, JLink lets you access Java and script with Mathematica code:

    Needs["JLink`"]
    LoadJavaClass["java.net.InetAddress"]
    InetAddress`getAllByName["localhost"]
    

    Hit Shift-Enter to evaluate, and you get

    {<>}
    

    Then you can use Mathematica's Map function to call toString on the returned objects:

    #@toString[]& /@ %
    

    to get the result (or to use the less obscure syntax, Map[Function[obj, obj@toString[]], %]):

    {"localhost/127.0.0.1"}
    

    If you start to get serious with this, you'll want to read Todd Gayley's tutorial at http://reference.wolfram.com/mathematica/JLink/tutorial/Overview.html.

提交回复
热议问题