Reputation: 491
I have a listener inside Class A, and I want to pass Class A to my Class B inside the listener. Normally I'd just use this, but then I'd get the event that triggered the listener.
Upvotes: 6
Views: 2462
Reputation: 2266
You can add a reference to class A in the constructor for the listener:
class_a_obj.addActionLister(new ActionListener(class_a_obj) { ...
Upvotes: 1
Reputation: 147164
A.this
.
(It is rare that the inner class this
is useful. Indeed it is relatively common to have bugs where the wrong this
was used. So it is unfortunate that it is the default. Not about to change after 12 years.)
Upvotes: 9