views:

64

answers:

2

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.

+3  A: 

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.)

Tom Hawtin - tackline
+1  A: 

You can add a reference to class A in the constructor for the listener:

class_a_obj.addActionLister(new ActionListener(class_a_obj) { ...
twolfe18