11

I just started using jshell in intellij idea community version. When I write the below code in jshell, it works.

List<String> list = List.of("a", "b", "c");
System.out.println(list);

However the same code doesn't work in intellij. It says "Expression expected". It executes fine but shows that there is error with List<String>. The problem is "auto-complete" doesn't work. To workaround this issue, we can use raw type but I want a generic one. Is there something that I am missing? How can I write a generic type?

Need Help
  • 113
  • 5
  • 1
    Aside - There seem to be a decent number of [bugs open on Jshell integration in IJ](https://youtrack.jetbrains.com/issues?q=jshell) – Naman Jun 14 '20 at 11:39
  • 2
    Please see the bug already created for the issue: https://youtrack.jetbrains.com/issue/IDEA-190187 – Olga Klisho Jun 15 '20 at 15:08

1 Answers1

11

Not an IntelliJ IDEA expert but I get my way around by writing a anonymous class:

new Object() {
    void method() {
        List<String> list = List.of("a", "b", "c");
        System.out.println(list);
    }
}.method();
Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67