• 泛型


    package fanxing;
    
    import java.util.ArrayList;
    import java.util.Collection;
    
    public class testdemo {
    public static void main(String[] args) {
    	//同一类型
    	Collection<String> a=new ArrayList<String>();
    	Collection<father> b=new ArrayList<father>();
    //	Collection<father> b=new ArrayList<son>();error
    	Collection<son> c=new ArrayList<son>();
    	//<? extends E>向下限定,E及其子类
    	Collection<? extends Object> d=new ArrayList<Object>();
    	Collection<? extends Object> e=new ArrayList<father>();
    	Collection<? extends Object> f=new ArrayList<son>();
    	Collection<? extends father> g=new ArrayList<son>();
    	//Collection<? extends father> h=new ArrayList<Object>();error
    	//<?>表示任意类型 Object或者其子类
    	Collection<?> a1=new ArrayList<son>();
    	Collection<?> a2=new ArrayList<father>();
    	Collection<?> a3=new ArrayList<Object>();
    	
    	//<? super E>向上限定 E及其父类
    	Collection<? super Object> b1=new ArrayList<Object>();
    	//Collection<? super Object> b2=new ArrayList<father>();error
    	//Collection<? super Object> b3=new ArrayList<son>();error
    	//Collection<? super father> b4=new ArrayList<son>();error
    	Collection<? super son> b2=new ArrayList<Object>();
    	Collection<? super father> b3=new ArrayList<Object>();
    	Collection<? super son> b4=new ArrayList<father>();
    	
    }
    
    	
    	
    }
    class father{
    	public void show(){
    		System.out.println("sss");
    	}
    }
    class son extends father{
    	public void show(){
    		System.out.println("son");
    	}
    }
    

      

  • 相关阅读:
    flex 居中并两端对齐
    搭建Docker环境---私有仓库registry搭建
    搭建Docker环境---常用命令
    搭建Docker环境---Docker安装(centos7)
    搭建Docker环境---Docker概述
    Shell脚本
    安装webstrom2019
    mysql主从配置
    MySql5.7安装(centos 7)
    MySQL父子节点查询
  • 原文地址:https://www.cnblogs.com/ysg520/p/9568330.html
Copyright © 2020-2023  润新知