Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 A 类中有一个监听器,我想在监听器内将 A 类传递给我的 B 类。通常我只会使用它,但随后我会得到触发监听器的事件。
A.this.
A.this
(内部类很少this有用。确实,在使用错误的地方出现错误是相对常见的this。所以不幸的是它是默认的。12年后不会改变。)
this
您可以在侦听器的构造函数中添加对 A 类的引用:
class_a_obj.addActionLister(new ActionListener(class_a_obj) { ...