I won’t go into detail here about what generics mean, and the definition of generic classes in Java is relatively simple, for example: public class Test
But generic methods in Java are more complicated.
   Specific type of generic types when instantiating the class.语 Define the generic format of generic method and grammar as follows:
Call the generic method and grammar format as follows:
To explain, when defining the generic method, you must add a & lt; t & gt;, come to come before the return value. Declare this to be a generic method, holding a generic T, and then use the generic T as the return value of the method.
The function of Class
Why use variable c to create objects? Since it is a generic method, it means that we do not know what the specific type is, nor what the construction method is, so there is no way to create a new object, but we can use the newInstance method of the variable c to create the object, that is, using reflection to create it. object.
The parameter required by the generic method is of type Class
Why use generic methods? Because a generic class needs to specify the type when it is instantiated, if you want to change to a different type, you have to create it again, which may not be flexible enough; while a generic method can specify the type when it is called, which is more flexible.