문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top