generics, also known as parameterized types, are used when defining classes, interfaces, and methods by indicating the type of object to be processed by the type parameter, which can be reused by many different types of objects
generic programming is implemented using inheritance before adding generic classes in Java. For type parameters, this code might be useful for all of the built-in classes, and the type variables in the class definition are used to specify the return type of the method and the type of the domain, local variable.
declaration of a generic method: in addition to generic classes, you can define only one method as a generic method, specifying either a method parameter or a return value of a generic type, to be determined when the method is called. A generic method can be declared in a generic class or declared in a normal class.
constraints and limitations of generic classes: type parameters cannot be instantiated with a base type, run-time type queries only apply to primitive types, cannot be thrown or catch generic class instances, arrays of parameterized types are illegal, type variables cannot be instantiated, type variables are invalid in static contexts of generic classes, note conflicts after Erasure
By understanding the three examples in the book, I learned how to define a generic class, introduce generic variables, define simple methods with type parameters, or more to understand code examples on a book, and learn by commenting on the code.
201671010106 2016--2017 "Java Programming" learning experience 8