Double brace initialization is an option:
List<String> symbolsPresent = new ArrayList<String>() {{
add("ONE");
add("TWO");
add("THREE");
add("FOUR");
}};
Note that the String
generic type argument is necessary in the assigned expression as indicated by JLS §15.9
It is a compile-time error if a class instance creation expression declares an anonymous class using the "<>" form for the class's type arguments.