General
Generics allow templating classes to specify types.
This is a list without generics:
List list;
String s;
list = new ArrayList();
list.add("hello");
s = (String) list.get(0);
This is the same list, specifying it contains Strings:
List<String> list;
String s;
list = new ArrayList<>();
list.add("hello");
s = list.get(0); // no casting
More Information
Last updated
Was this helpful?