As has been suggested in the comments, the reason for the error is probably that you've imported the wrong List
. What you wanted was a java.util.List
which can take generics, whereas you've probably imported java.awt.List
, which can't. Changing the import statement to bring in the correct type should solve the problem.
The returned-value type of Arrays.asList in Java [closed]
-
09-10-2022 - |
题
The following line is copied directly from the documentation of the Arrays.asList()
method:
List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
When trying this line in my code, I get the following compilation error:
The type List is not generic; it cannot be parameterized with arguments
My question is why?
To be more specific, how can this method return a List<String>
object if List
is not generic?
解决方案
不隶属于 StackOverflow