Code written with a generic mechanism has better security and readability in code that enforces type conversions than those that are cluttered with variables that use the type object.
Generic class:
The type variable t is placed after the class name, with <>, and the generic class can be regarded as the factory of the ordinary class.
Generic methods:
The generic is placed after the modifier and returns the front of the type.
Qualification of generic type variables:
Whether a generic type is defined appropriately, a corresponding primitive type erase type variable is automatically supplied, replaced with a qualified type (No limit to object)
The compiler automatically inserts force type catch.
Constraints:
- You cannot instantiate a generic parameter with a base type
- Run-time type queries apply only to the original type (a instanceof pair<string>, false)
- Cannot create an array of parameterized types
- Cannot instantiate type variable (new T ())
- Cannot reference a type variable in a static field or method
- An instance of a generic class cannot be thrown or captured
Two classes have an inheritance relationship, the generic class is not connected
Wild-Letter wildcard types:
Wildcard characters can also specify a super-type qualification:? Super Manager
Wildcard characters with a super-type qualification can be written to generic objects, and wildcard characters with sub-type qualification can be read from generic types.
Java Trivia Point 6