Essentials of java knowledge (2)

Time:2020-1-15

I. set
1. Iterable v.s. Iterator
Both are interfaces, and the inherited interface in collection is Iterable.
Iteratable expresses that the collection has the ability of iterative access, while iterator represents the implementation, which can be from small to large or from large to small.
https://zhuanlan.zhihu.com/p/52366312

2. Comparable v.s. Comparator
    https://www.cnblogs.com/skywang12345/p/3324788.html

3. set
    https://www.cnblogs.com/LittleHann/p/3690187.html
    Collection needs multi-purpose

Two. Generic
1. ListAs a concrete type, unreal logical type
List l1 = new ArrayList< String >();
List l2 = new ArrayList< Integer >();
System.out.println(l1.getClass() == l2.getClass() );
Result?

Therefore, static members of a class cannot use type parameters.
    public class R{
        Static t info; // error
        Static void test (t MSG); // error
    }

2. ?, ? extends type, ? super type      
    1) Wildcard and inheritance relationship
    There is no inheritance relationship between list and list.
        Void test (List L) passing in list will compile and report an error

    Wildcards and their upper and lower limits can be understood as supplements to inheritance relationships.
    Void test (list > L) function can receive list, list, etc
    Void test (list extensions numbers > L) function can receive list, list, etc.

    2) Understand the following code, where rect is a shape subclass
        void addRect(List< ?  extends Shape> shapes){
            shapes.add(0, new Rect());
        }

Three, abnormal
The purpose of exception design is to separate business logic from exception handling logic.
When an exception occurs in the running process of a java program, the system automatically generates an exception object, which is submitted to the Java runtime;
When the Java runtime receives the exception object, it looks for the appropriate catch block. If not, the Java program exits.

1. try...catch...finally
    The finally code block will be executed unless try or catch calls System.exit.
    Return, throw in try or catch will be executed after the finally block

2. Abnormal system
    Throwable
        -> Error  
        -> Exception
            -> RuntimeException
            ->Others...: checked exception must show handling

Recommended Today

RCAST 35: add type to currency

– font ALT: Simsun; MSO font charset: 134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:”Cambria Math”; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; Variable; Ose-1: 216301111; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /\* Style […]