Generic type:
* Generics are types in Java
* Java.lang.Type can represent all types in Java
* Generics are parameterized types
* Type--->class
* Parameterized-->class type can pass parameters
* Meaning of the existence of generics
* polymorphic
Actual type and required type may not match
ClassCastException errors are reported if they do not match
* Generics can tell class type at compile time, pass parameters
is what type, if the type is wrong, then at compile time will be
Error
* The form represented by generics
* arraylist<t>
* ArrayList is class type
* ArrayList with a parameter of t,t is a formal parameter
* When creating a ArrayList object, you can determine the argument
* Performance:arraylist<person> a = new arraylist<person> ();
This argument is person, which means that only the person is stored in a collection
* Public Interface persondao<t>{
}
public class basedaoimpl<t>{
}
public class Persondaoimpl extends basedaoimpl<person> implements persondao<person>{
}
* public class person<? Extends collection> passed parameters can only be subclasses of the collection
* Usage of generics
public class person<t>{
}
The parameter T can be used on properties and methods (which can be used on the parameters and return values of the method)
Representation of generics