Jshell in intellij doesn't allow generic types

Viewed 751

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?

1 Answers

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();
Related