1

In most of scripting/interpreting programming languages such as python or JavaScript, there is/are a/some method(s) to execute a string in runtime just like a code. For example: eval("int i=5;"); those could have run the eval method inside the interpreting shell and even inside the input parameter of eval method recursively without a problem. In jshell I found, inside the java host program after creating a jshell object we can call the eval, but what if I want to insert the eval inside the string and then run it in the jshell object. For example:

 JShell jsh=JShell.create();
 jsh.eval("int j=4;");//current way of using eval in jshell hosted by another java or jshell program.

I need to do something like this:

 JShell jsh=JShell.create();
 jsh.eval("""
 eval("int j=4;");
 """);

or alternatively

JShell jsh=JShell.create();
jsh.eval("""
 currentJShell.eval("int j=4;");
 """);

after some research, I found something like "/open" doesn't solve the problem for multiple reasons: 1- it's a part of interactive jshell utility/UI (provided (probably) by oracle(not sure)) not exactly jshell object 2- even if it is a part of jshell, still inside the guest jshell program, I can't call it in a for loop or ... I have to type it with the keyboard and then hit enter.

for(int c=0;c<34;c++){/open <filename+c>}// it's not possible.

But in beanshell looks like ok just like python and JavaScript. I have the same problem with csharp script. Thanks for your time. Sorry if this question is asked in the wrong spot. I am not very familiar with these types of q/a website.

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
Maj
  • 29
  • 4

0 Answers0