zoukankan      html  css  js  c++  java
  • 019.1泛型

     内容:泛型类、泛型接口;

    泛型擦除:编译器时期有泛型,在运行时期没有

    ######泛型类
    为了是各种类型的一些共有方法对象。

    public class FanLeiDemo
    {
        public static void main(String[] args)
        {
            Util<Student> util = new Util<Student>();
            util.setObj(new Student());
            Student stu = util.getObj();
            System.out.println(stu);
        }
    }
    
    class Util<X>{
        private X obj;
        public X getObj()
        {
            return obj;
        }
    
        public void setObj(X obj)
        {
            this.obj = obj;
        }
    }
    
    class Student{
        private String name;
        private int age;
        public String getName()
        {
            return name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getAge()
        {
            return age;
        }
        public void setAge(int age)
        {
            this.age = age;
        }
    }

    #######泛型方法

    public class FanLeiDemo
    {
    
        public static void main(String[] args)
        {
            Util<Student> util = new Util<Student>();
            util.setObj(new Student());
            util.show(222);
            util.show("xx");
        }
    }
    
    class Util<X>{
        private X obj;
    
        public X getObj()
        {
            return obj;
        }
    
        public void setObj(X obj)
        {
            this.obj = obj;
        }
        public <W>void show(W w){   //泛型方法
            System.out.println(w);
        }
    }

    泛型接口

    通配符

  • 相关阅读:
    python 安装mysql-python模块
    Linux 目录结构
    python logging 配置
    mac下docker使用笔记
    centos yum 使用笔记
    python 正则使用笔记
    django 动态更新属性值
    nginx 反向代理
    yii2 高级版新建一个应用(api应用为例子)
    tfn2k工具使用介绍
  • 原文地址:https://www.cnblogs.com/-nbloser/p/8733186.html
Copyright © 2011-2022 走看看