It is called a type parameter. It means that ArrayList will contain only objects of type Lot Check out the concept of Generics .
You will get the use of this ArrayList<Lot> with this example:
// (a)Without Generics .... List myIntList = new ArrayList(); // 1 myIntList.add(new Lot(0)); // 2 Lot x = (Lot) myIntList.iterator().next(); // 3 // (b)With Generics .... List<Lot> myIntList = new ArrayList<Lot>(); // 1' myIntList.add(new Lot(0)); // 2' Lot x = myIntList.iterator().next(); // 3
Two points that should be noted in the above example, for example,
- In
eg(b) . Since we have already indicated that the ArrayList will contain only objects of the Lot, in Line 3 , we did not have to cast it to dial the Lot object. This is because the compiler already knows that it will only have an object of type Lot. - Attempting to add any other type of object to
eg (b) will result in a compile-time error. This is because the compiler has already identified this list, which contains only elements of type Lot . This is called type checking
source share