zoukankan      html  css  js  c++  java
  • 泛型

    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");
    	}
    }
    

      

  • 相关阅读:
    注释
    Servlet原理和开发
    什么是Servlet
    Java基础目录
    实现第一个Servlet
    Servlet的体系
    习题3
    利用ResultFilter实现asp.net mvc3 页面静态化
    oracle欲出纯托管代码的ODP.NET,现接受小范围预览版本使用申请
    http请求头中包含未编码中文时webapi self host崩溃
  • 原文地址:https://www.cnblogs.com/ysg520/p/9568330.html
Copyright © 2011-2022 走看看