gpt4 book ai didi

java - 传入 'This' 关键字

转载 作者:行者123 更新时间:2023-11-29 08:03:05 28 4
gpt4 key购买 nike

<分区>

public class CommandForm extends Form implements CommandListener {

Display d;

public CommandForm(String msg) {

super(msg);
this.addCommand(exit);

}


private void showMessage(String title, String text) {
Alert a = new Alert(title, text, null, AlertType.INFO);
d.setCurrent(a, this);

}

public void prepare_view(Display d){
this.setCommandListener(this);
this.d = d;
}

public void show_view(){
d.setCurrent(this);
}
}

我不知道这个例子中“this”关键字的确切含义。我的讲师说它是当前对象,当我进一步询问时,他说它是 CommandForm。那是对的吗?当您将“this”传入括号时,例如 setCommandListener(this) 您实际上是在传递 CommandForm 吗?我知道如何使用“this”的唯一方法就是这样,this.d = d。所以这对我来说有点新鲜。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com