The purpose of Java generics:
versatility, which can be applied to multiple types rather than to a specific interface or class.
JAVA1.5 's supplement.
used to specify what type of object the container is to hold, and the compiler guarantees the correctness of the type.
Core concepts of Java generics:
tell the compiler what type you want to use, and the compiler can help you with all the details.
Limitations of Java generics :
1, you cannot use the base type as a type parameter.
-java Generic methods :
You can use generic methods to use generic methods as much as possible.
static method, cannot access the type parameter of the generic class.
define a generic method: Define a generic parameter list before the return value
Public static <T> void Test () {
}
(when you use a generic class, you must specify the value of the type parameter when you create the object, and when you use a generic method, you typically do not have to indicate the type of the parameter, because the compiler finds the specific type for you.) This is called type parameter inference. )
when specifically implemented, the compiler cannot infer the type as
list<person> List = new arraylist<person> ();
call the generic method, display the type description, insert the type between the. operator and the method name
new Generator (). <suborder>test (new Suborder ());
Java Generic Notes