I think I understand the basics of anonymous classes, but I would like to clarify something. when i have syntax like
class A { class AnonymousClass1 Implements ActionListener{} } class A { public A() { JButton btn = new JButton(); btn.addActionListener( new ActionListener(){} ); } }
If the anonymous class is actually an inner class of class A, as in the first example: in theory, is the semantics correct?
What exactly is going on? I think that when the java file is compiled, a .class file is created for the anonymous class, so it can be referenced (but I could not find it). When an instance of object A is created, it creates a button object, then btn calls the addActionListener () method, which actually passes something like this btn.addActionListener(new AnonymousClassOne()) AnonymousClassOne is the common name given by the compiler.
If this is not so? Thank.
java anonymous-class anonymous-inner-class
Lews Therin Oct. 15 2018-11-11T00: 00-10
source share