1. In exception handling, if a subclass overrides a method of the parent class, the checked exception declared in the subclass method cannot be declared more than the parent class method. The exception is more general, that is, the subclass method can throw a more specific exception (does not exceed the exception scope declared by the parent class method, that is, the child exception derived from the exception declared by the parent class method ), or no exception is thrown. Also, if the parent class method does not throw an exception, the subclass cannot throw any checked exceptions.
Personal understanding: Due to the polymorphic characteristics of object-oriented, that is, the parent class can refer to the subclass object and access the subclass method through the parent class to achieve polymorphism (rewriting). In this call chain, the subclass method cannot throw exceptions that the parent class method cannot accept, that is, the exceptions declared by the parent class should be more general.
1. The definition of a generic class is to declare the generic parameters after the class name, such as A
Basic principles: Try to use generic methods, that is, generic methods replace generic classes; in addition, for static methods, The type parameters of a generic class cannot be accessed, so if a static method requires generics, a generic method must be used.
2. When using a generic class, the value of the type parameter must be specified when creating the object; when using a generic method, it is usually not necessary to specify the parameter type. The compiler can find it through "type parameter inference" Concrete type (so a generic method can accept any type).
The above is the detailed content of Summary of JAVA learning knowledge points. For more information, please follow other related articles on the PHP Chinese website!