Java generic summary, java generic
Generic summary:
1. generics have the ability to parameterize types. You can define classes or methods that use generic types. The compiler will replace generic types with specific types.
2. The main advantage of generics is the ability to detect errors during compilation rather than during runtime.
3. The generic class or method allows you to specify the object type that this class or method can contain. If you try to use a class or method with incompatible objects, the compiler may detect this error.
4. The generic type defined in the class, interface, or static method is called the form introspection type. Then, you can replace it with an actual specific type. The process of replacing the generic type is called the generic instantiation.
5. generic classes that do not use type parameters are called the original type, for example, ArrayList. The original type is used to be backward compatible with earlier Java versions.
6. There are three types of general type :? ,? Extends T ,? Super T. here T represents a generic type.
1) The first form ,? It is called an unrestricted wildcard? The extends Object is the same.
2) What is the second form? Extends T is called a restricted configuration, which represents a subtype of T or T.
3) What is the third form? Super T is called the lower limit wildcard, indicating a parent type of T or T.
7. Use a method called type elimination to implement generics. the compiler uses generic class information to compile code, but then eliminates it.
Therefore, generic information is unavailable at runtime. This method can make generic code backward compatible with legacy code of the original type.
8. You cannot use generic parameters to create objects.
9. You cannot use generic parameters to create arrays.
10. You cannot use tired generic parameters in a static environment.
11. You cannot use generic parameters in the exception class.