zoukankan      html  css  js  c++  java
  • Java泛型深入题目

    //Java泛型. 程序是从网上看到的,很具有代表性。
    //已知 Apple extends Fruit extends Object
    //指出下列语句的正确性,并解释。




    import java.util.ArrayList;
    import java.util.List;
    
    
    public class GenericTest {
    
    
        public static void main(String[] args) throws SQLException {
    
    
           List<? super Fruit> f0=new ArrayList<Fruit>();
           f0.add(new Apple());
           f0.add(new Fruit());
           f0.add(new SupApple());
           
           List<? super Fruit> f1=new ArrayList<Apple>();
           f1.add(new Apple());
           f1.add(new Fruit());
           
           List<? extends Fruit> f2=new ArrayList<Fruit>();
           f2.add(new Apple());
           f2.add(new Fruit());
           
           
           List<? extends Fruit> f3=new ArrayList<Apple>();
           f3.add(new Apple());
           f3.add(new Fruit());
            
           List<? super Apple> f5=new ArrayList<Fruit>();
           f5.add(new Apple());
           f5.add(new SupApple());
           f5.add(new Fruit());
        }
    }
    
    
    class Fruit{
    }
    
    
    class Apple extends Fruit{
    }
    
    
    class SupApple extends Apple{    
    }


  • 相关阅读:
    python2和python3的区别
    星球大战
    [USACO]高低卡(金)High Card Low Card (Gold)
    学习笔记
    叶子的染色
    大问题
    ...
    考试前...
    [HAOI2010]计数
    [POI2006]OKR-Periods of Words
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6467135.html
Copyright © 2011-2022 走看看