In definition of generic Class add()
method(shown below code) ,what is this.t
doing. i mean what is " this
" term here ? we didn't define any constructor name called this
anywhere right ? is this predefined object ?
public class Box<T> {
private T t;
public void add(T t) {
this.t = t; // what is " this " term here ?
}
public T get() {
return t;
}
public static void main(String[] args) {
Box<Integer> integerBox = new Box<Integer>();
Box<String> stringBox = new Box<String>();
integerBox.add(new Integer(10));
stringBox.add(new String("Hello World"));
System.out.printf("Integer Value :%d\n\n", integerBox.get());
System.out.printf("String Value :%s\n", stringBox.get());
}
}