I have a code :
public class App {
public static void main(String[] args) {
System.out.println("Hello World from main!");
JShell shell = JShell.builder().build();
shell.eval("System.out.println(\"Hello World from JShell!\");");
}
}
Now I want that I can set the output stream for the JShell only and not the normal code.
I tried :
shell.eval("System.setOut(new Printer());");
shell.eval("System.out.println(\"Hello World!\");");
But does not work!
My Printer class:
class Printer extends PrintStream{
public Printer() {
super(System.out);
}
@Override
public void print(String s) {
super.print("Message: - " + s);
}
}