java static final generic class object

java static final generic class object

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()+"\n");

tc.setT(new Integer(102));

System.out.println("tc.t: "+tc.getT()+"\n");

tc.setT(new Integer(103));

System.out.println("tc.t: "+tc.getT()+"\n");

//tc = new TestClass<Integer>(); //cannot assign new value to a final object

}

}

 

operation result:

tc.t: 101

tc.t: 102

tc.t: 103

 

 

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/aspirs/p/11446685.html