zoukankan      html  css  js  c++  java
  • java static final泛型类对象

    java static final泛型类对象

    class TestClass<T> {
    public T t;
    
    public void setT(T t) {
    
    this.t = t;
    
    }
    
    public T getT() {
    
    return t;
    
    }
    
    }
    
    public class StaticObj {
    
    public static final TestClass<Integer> tc = new TestClass<Integer>();
    
    public static void main(String[] args) {
    
    tc.setT(new Integer(101));
    
    System.out.println("tc.t: "+tc.getT()+"
    ");
    
    tc.setT(new Integer(102));
    
    System.out.println("tc.t: "+tc.getT()+"
    ");
    
    tc.setT(new Integer(103));
    
    System.out.println("tc.t: "+tc.getT()+"
    ");
    
    //tc = new TestClass<Integer>(); //cannot assign new value to a final object
    
    }
    
    }
    

    运行结果:

    tc.t: 101

    tc.t: 102

    tc.t: 103

      

  • 相关阅读:
    案例分析
    202103226-1 编程作业
    阅读任务
    准备工作
    结对作业
    案列分析
    202103226-1 编程作业
    《构建之法》有感
    准备工作
    案例分析作业
  • 原文地址:https://www.cnblogs.com/aspirs/p/11446685.html
Copyright © 2011-2022 走看看