zoukankan      html  css  js  c++  java
  • 泛型的嵌套

    class InfoDemo <T, V>{
     private T var;
     private V value;
     public InfoDemo(T var, V value){
      this.setvalue(value);
      this.setvar(var);
     }
     public void setvar(T var){
      this.var = var;
     }
     public void setvalue(V value){
      this.value = value;
     }
     public T getvar(){
      return this.var;
     }
     public V getvalue(){
      return this.value;
     }
    }
    class Demo <S>{
     private S InfoDemo;
     public Demo(S InfoDemo){
      this.setInfo(InfoDemo);
     }
     public void setInfo(S InfoDemo){
      this.InfoDemo = InfoDemo;
     }
     public S getInfoDemo(){
      return this.InfoDemo;
     }
    }
    public class GenericsDemo5 {
     public static void main(String[] args) {
      InfoDemo<String, Integer> Inf = new InfoDemo<String, Integer>("张三", 30);
      Demo<InfoDemo<String, Integer>> Dem = new Demo<InfoDemo<String,Integer>>(Inf);
      System.out.println("姓名: " + Inf.getvar());
      System.out.println("年龄:" + Inf.getvalue());
      System.out.println("姓名: " + Dem.getInfoDemo().getvar());
      System.out.println("年龄:" + Dem.getInfoDemo().getvalue());
     }
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    【HTML】input标签中alt属性和title属性的比较
    【HTML】WWW简介
    【MySQL】MySQL的常规操作
    iOS编程(双语版)
    Swift语言精要
    Swift语言精要
    python网络爬虫
    Python小任务
    如何在onCreate方法中获取视图的宽度和高度
    python网络爬虫
  • 原文地址:https://www.cnblogs.com/penggy/p/4786506.html
Copyright © 2011-2022 走看看