0

I can type

ArrayList<T> l = new ArrayListList<T>();

and

List<T> l = new ArrayList<T>(); 

but Java does not allow me to use

List<T> l = new List<T>();

Why?

Pshemo
  • 122,468
  • 25
  • 185
  • 269
sammy333
  • 1,384
  • 6
  • 21
  • 39
  • 13
    Because `List` is an interface – ಠ_ಠ Jul 21 '14 at 19:19
  • `List` is an interface. You cannot instantiate an interface. `ArrayList` is a class, which is an implementation of `List`. Classes can be instantiated. – forgivenson Jul 21 '14 at 19:20
  • 1
    You may want to read this [tutorial](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html). It's about abstract classes, but a lot of it applies to interfaces also. – ajb Jul 21 '14 at 19:39

1 Answers1

2

List is an interface, and so it has no method implementations and cannot be instantiated. Your first two examples instantiate an ArrayList, which is a non-abstract class which implements the List interface.

sumitsu
  • 1,481
  • 1
  • 16
  • 33