0

I am new in Java.I tried to collect some Callable by List.

List<Callable<Long>> callables=new ArrayList<>()

But complier gave me "Cannot infer type arguments for ArrayList<>". Then I chang the code to :

List<Callable<Long>> callables=new LinkedList<>();

There is no error message.why I can't use ArrayList to Implement?? Thanks!!

  • 3
    Post the full code, with imports. This should work if we're talking about `java.util.ArrayList` and `java.util.List`. – Tunaki Jun 07 '16 at 13:52
  • Do you have your own class named `ArrayList` which is being picked up instead of the standard class `java.util.ArrayList`? Remove it or rename it. Don't give classes the same name as standard classes. – Jesper Jun 07 '16 at 14:10
  • Without type arguments compiler would complain for both ArrayList and LinkedList. As @Tunaki mentioned, please post full code. – SVashisth Jun 07 '16 at 14:45
  • 1
    @SVashisth Well, since Java 7, it would compile both. http://stackoverflow.com/questions/4166966/what-is-the-point-of-the-diamond-operator-in-java-7 – Tunaki Jun 07 '16 at 14:46
  • I am so stupid.As whst @Jesper said there is a class named ArrayList in the same package.Aftert I remove it,there is no error message.Thank everyone!! – Chiming Hsu Jun 08 '16 at 00:30

0 Answers0