jshell

How to import a custom class in intellij JShell console

杀马特。学长 韩版系。学妹 提交于 2019-11-30 20:08:04
I am using the new intellij Jshell console (introduced here https://blog.jetbrains.com/idea/2017/09/java-9-and-intellij-idea/ ) I created a simple class file Test2.java public class Test2 { public static String test(){ return "Hello"; } } The JShell console is able to find the method in the hints when i try to run this on intellij jshell console (Tools>Jshell Console) Test2.test(); I get the following error "C:\Program Files\Java\jdk-9.0.1\bin\java" --add-modules java.xml.bind -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.1\lib\jshell-frontend.jar;C:\Program

Is there a way to use method references for top-level functions in jshell?

倖福魔咒の 提交于 2019-11-30 17:48:30
Suppose I do this in jshell: jshell> void printIsEven(int i) { ...> System.out.println(i % 2 == 0); ...> } | created method printIsEven(int) jshell> List<Integer> l = Arrays.asList(7,5,4,8,5,9); l ==> [7, 5, 4, 8, 5, 9] jshell> l.forEach(/* ??? */); // is it possible to use a method reference here? In a normal program I could write l.forEach(this::printIsEven) in a non-static context or l.forEach(MyClass::printIsEven) in the static context of a class named MyClass . Using this::printIsEven in jshell doesn't work because jshell executes statements in a static context, but you can't use a static

Is there a way to use method references for top-level functions in jshell?

浪尽此生 提交于 2019-11-30 16:45:53
问题 Suppose I do this in jshell: jshell> void printIsEven(int i) { ...> System.out.println(i % 2 == 0); ...> } | created method printIsEven(int) jshell> List<Integer> l = Arrays.asList(7,5,4,8,5,9); l ==> [7, 5, 4, 8, 5, 9] jshell> l.forEach(/* ??? */); // is it possible to use a method reference here? In a normal program I could write l.forEach(this::printIsEven) in a non-static context or l.forEach(MyClass::printIsEven) in the static context of a class named MyClass . Using this::printIsEven in

How to execute a java script with jshell?

☆樱花仙子☆ 提交于 2019-11-30 11:57:07
问题 Given that Java 9 is upon us and we can finally have a java REPL with jshell I was hoping there was a way to add a shebang to a script and have jshell interpret it. I tried creating test.jsh : #!/usr/bin/env jshell -s System.out.println("Hello World") /exit However that gives: ⚡ ./test.jsh | Error: | illegal character: '#' | #!/usr/bin/env jshell -s | ^ | Error: | illegal start of expression | #!/usr/bin/env jshell -s | ^ Hello World It turns out there is an enhancement request for this in

Java 11 JShell inside Intellij IDEA

假装没事ソ 提交于 2019-11-30 11:45:55
I have Java 11 JDK and IntelliJ IDEA 2018.2.4 (64-bit). When I was using Java 10.0.2, the JShell console in IntelliJ IDEA worked fine. Now that I've upgraded to Java 11, the JShell console has stopped working. Nothing at all happens when I click on the Run button or when I hit Ctrl+Enter (see screenshot). My projects compile and run just fine using Java 11 - it's only the JShell console that doesn't work. (Also, JShell works fine from the Command Prompt, it's only inside IDEA that it doesn't work.) I can reproduce this issue on two machines, one at home running IDEA Community Edition 2018.2.4

What is the exact meaning / purpose of the J and R flags in jshell?

百般思念 提交于 2019-11-30 04:03:38
问题 From the help information: -J<flag> Pass <flag> directly to the runtime system. Use one -J for each runtime flag or flag argument -R<flag> Pass <flag> to the remote runtime system. Use one -R for each remote flag or flag argument I cannot find an explanation in both the tools documentation and jshell user guide. Also, what is "the remote runtime system" in the context of jshell? 回答1: As I understand it, JShell has 3 main 'places' to execute code: In the current process (see

Java 11 JShell inside Intellij IDEA

人走茶凉 提交于 2019-11-30 02:52:09
问题 I have Java 11 JDK and IntelliJ IDEA 2018.2.4 (64-bit). When I was using Java 10.0.2, the JShell console in IntelliJ IDEA worked fine. Now that I've upgraded to Java 11, the JShell console has stopped working. Nothing at all happens when I click on the Run button or when I hit Ctrl+Enter (see screenshot). My projects compile and run just fine using Java 11 - it's only the JShell console that doesn't work. (Also, JShell works fine from the Command Prompt, it's only inside IDEA that it doesn't

How to execute a java script with jshell?

折月煮酒 提交于 2019-11-30 01:48:57
Given that Java 9 is upon us and we can finally have a java REPL with jshell I was hoping there was a way to add a shebang to a script and have jshell interpret it. I tried creating test.jsh : #!/usr/bin/env jshell -s System.out.println("Hello World") /exit However that gives: ⚡ ./test.jsh | Error: | illegal character: '#' | #!/usr/bin/env jshell -s | ^ | Error: | illegal start of expression | #!/usr/bin/env jshell -s | ^ Hello World It turns out there is an enhancement request for this in OpenJDK https://bugs.openjdk.java.net/browse/JDK-8167440 . Is there any other way to do this? Use //usr

final variables are not functioning well in jshell

不问归期 提交于 2019-11-29 07:12:14
I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is some other way to work with final variables in jshell? While creating a final variable at the top-level

Is it possible to use sysout without class and main method in Eclipse IDE using Java 9?

给你一囗甜甜゛ 提交于 2019-11-29 04:19:01
As Java 9 introduced the concept of JShell which enables us to write code without creating a class and a method, is it possible to use this feature of Java 9 in eclipse ? vladul You can use the TM Terminal to run JShell in Eclipse: If necessary, install TM Terminal (contained only in some Eclipse packages) Open a 'Terminal' view in Eclipse: Window > Show View > Other...: Terminal > Terminal Launch a new Local Terminal Run JShell, e. g. on Windows type "C:\Program Files\Java\jdk-9\bin\jshell" -v followed by Enter Alternatively , you can use a Scrapbook Page , a built-in feature of the Eclipse