DESKTOP-94E2ELT_20200908-刘雪丽

一、问题

1、上课没有太理解的一个问题:就是复制后比较的那个问题,可能是那块过的比较快,没有太理解

public static void main(String[] args) {
        
        List<Integer> source = List.of( 100 , 20 , 99 , 78 , 9527 , 1 , 0 , -8526 );
        System.out.println( source );
        
        System.out.println( "- - - - - - - - - - - - - - - - - - - - - - -" );
        
        List<Integer> list = List.copyOf( source );
        System.out.println( list );
        
        System.out.println( source == list ); // true
        
        System.out.println( "- - - - - - - - - - - - - - - - - - - - - - -" );
        
        Collection<String> collection = Set.of( "王盼盼" , "怎么又是你" , "达旭辉" );
        System.out.println( collection );
        List<String> x = List.copyOf( collection );
        System.out.println( x );
        System.out.println( collection == x );
        
    }

现在的理解是:第一次比较的两个变量是因为他俩的运行时类型相同,所以直接复制(复制变量中的地址)后,是指向同一个对象,所以返回true。第二次比较的变量他俩的运行时类型不同,所以需要再new一个List,内容跟collection一样,但跟原来变量指向的对象不是同一个。所以他俩不同,返回false。