zoukankan      html  css  js  c++  java
  • java 统一输入泛型类型

     1 class Info<T>{
    2 private T var;
    3 public T getVar(){
    4 return var;
    5 }
    6 public void setVar(T var){
    7 this.var=var;
    8 }
    9 public String toString(){
    10 return this.var.toString();
    11 }
    12 }
    13 public class GenericsDemo {
    14 public static void main(String[] args) {
    15 Info<String> i1=new Info<String>();
    16 Info<String> i2=new Info<String>();
    17 i1.setVar("hello");
    18 i2.setVar("LiXinghua");
    19 add(i1,i2);
    20 }
    21 public static <T> void add(Info<T> i1,Info<T> i2){
    22 System.out.println(i1.getVar()+" "+i2.getVar());
    23 }
    24 }
  • 相关阅读:
    HDU 2795
    HDU 1394
    HDU 1754
    HDU 1166
    SDOI 2006
    HDU 1423
    HDU 1561
    centos7.4 搭建zabbix-server 3.4.5
    vim 简单笔记
    jdk环境并配置环境变量
  • 原文地址:https://www.cnblogs.com/dennisac/p/2396549.html
Copyright © 2011-2022 走看看