The flag you would like to apply is:
"-source 8"
The way to pass this onto the compiler behind JShell would be:
"jshell -C "-source 11"
... But it won't work. I tried it just now, and the Jshell fails to parse this with an exception. It should not be the case, so I looked into the code of the Arguments class that throws the error. It turned out that javac
options are grouped into different categories, and only the BASIC
commands are allowed via JShell (com.sun.tools.javac.main.Option.java:1308).
Setting the source flag does not belong to this group, so the validator throws it out and the setting will not be applied.
If you want to verify this, you can try to pass a BASIC type of param to the javac like "-p", and you will see it correctly passed.