JShell is the interactive REPL command line for Java.
If I have a Java class with some methods that I would like to play around with interactively in a .java file, how do I load that file in?
Let's say I have the file HelloWorld.java
:
class HelloWorld
{
public static void main(String[] argsv)
{
}
public static void doStuff()
{
System.out.println("Hello world");
}
}
and I'd like to load up JShell and be able to call the doStuff()
method from the command line. How do I do that?
Starting JShell
with the file name as $ JShell HelloWorld.java
didn't work. Nor classfile. I still get the error cannot find symbol | symbol: variable HelloWorld
from JShell. Using the /open <filename>
command gave same result.