Java 泛型类方法中该术语的含义?

Java 泛型类方法中该术语的含义?,java,Java,在泛型类add()方法(如下代码所示)的定义中,this.t在做什么。我的意思是这里的“这个”术语是什么?我们没有定义任何名为this的构造函数名,对吗?这是预定义的对象吗 public class Box<T> { private T t; public void add(T t) { this.t = t; // what is " this " term here ? } public T get() { r

在泛型类
add()
方法(如下代码所示)的定义中,
this.t
在做什么。我的意思是这里的“
这个
”术语是什么?我们没有定义任何名为
this
的构造函数名,对吗?这是预定义的对象吗

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());
    }
}
公共类框{
私人T;
公共无效添加(T){
this.t=t;//这里的“this”是什么?
}
公共部门得不到{
返回t;
}
公共静态void main(字符串[]args){
Box integerBox=新的Box();
Box stringBox=新的Box();
integerBox.add(新的整数(10));
添加(新字符串(“Hello World”);
System.out.printf(“整数值:%d\n\n”,integerBox.get());
System.out.printf(“字符串值:%s\n”,stringBox.get());
}
}
公共类框{
私人T;
公共无效添加(T){
this.t=t;//这里的“this”是什么?
}

this.t
引用的是当前Box实例(which是实际的私有变量)。基本上这是一个setter。你可以阅读更多关于setter的内容。希望这有帮助!

这个
构造函数,但它在这里引用当前的
实例。
这个
引用对象的实例,因为参数是
t
,类的属性也是
t
,所以使用e> 这
您可以区分哪个是哪个
public  class Box<T> {
    private T t;

    public void add(T t) {
        this.t = t; // what is " this " term here ?
    }