| Author |
Using final for anonymous inner classes.
|
Adam Till
Ranch Hand
Joined: Oct 11, 2002
Posts: 41
|
|
Hi all I have a method that creates a JFrame, within this is a button that has an anonymous inner class that disposes of the frame. The JFrame has to be final so it can be referenced in the anonymous inner class, what are the consequences of having a JFrame final? I suspect not much as it only makes the reference to the JFrame constant. Is this correct? Thanks
|
Adam Till<br />SCJP SCJD SCWCD
|
 |
Michael Ernest
High Plains Drifter
Sheriff
Joined: Oct 25, 2000
Posts: 7292
|
|
|
Making the JFrame in the top-level final puts the JFame in-line with the compiled class, where any inner class is guaranteed it can complete a reference. An anonymous inner class would not be able to refer to an element outside its top-level class, so insisting on the final scope avoids trouble.
|
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
|
 |
 |
|
|
subject: Using final for anonymous inner classes.
|
|
|