Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top