1, the generic solution to the security of the element storage, to solve the acquisition of data elements, the need for the type of strong-turn problem.
--the core idea of generics: to limit the content in a collection to a specific data type.
2, the use of generics
1) use in the collection
2) Custom generic class, generic interface, generic method
3) The relationship between generics and inheritance
4) wildcard characters
3, if the generic class, the generic interface does not use generics, the default is the object type.
4. When inheriting a generic class or generic interface, you can indicate the type of the generic type.
5. Definition of generic method:
public <E> e Gete (e e) { return e;}
6. Class A is a subclass of class B, but list<a> is not a list<b> sub-interface.
7. The use of:list<a>, List<b> Are all list<?> sub-interfaces.
--? Extends a: can store a and its subclasses;
--? Super A: Can hold a and its parent class.
--The object is not allowed to be written to a collection class declared as a wildcard, but can be read.
8, the generic note points:
1) The generic type of the class cannot be used in a static method;
2) If the generic class is an interface or abstract class, the object of the generic class cannot be created;
3) cannot use generics in catch
4) derive subclasses from generic classes, and generic types need to be materialized.
Java notes-Generics