I want to create an empty list of type List<String>
in jshell
I am hoping jshell
supports some sort of syntax shorthand for example:
List<String> args = []
However it failed with this error message:
| Error:
| illegal start of expression
| List<String> args = [];
| ^
Of course I can just use the standard java expression:
import com.google.common.collect.ImmutableList
List<String> args = ImmutableList.of()
but I want to know if it can be more terse.
If you're initialising a List
you can do it as:
List<String> list = List.of();
If instead it was an array, you could have initialized it as :
String[] arr = {}