Home > Java > javaTutorial > Summary of JAVA learning knowledge points

Summary of JAVA learning knowledge points

巴扎黑
Release: 2017-06-23 16:33:02
Original
1428 people have browsed it

Exception handling

 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.

Generics

1. The definition of a generic class is to declare the generic parameters after the class name, such as A; whether the generic method is the same as the class in which it is located. It doesn't matter if it is generic, the way to define it is to just put the generic parameters before the return value.

 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template