May 29th, 2013, 04:29 AM
private final class???
Hello, please explain why someone would declare such an inner class?
and especially why final if its a private class?
May 29th, 2013, 12:27 PM
Re: private final class???
You declare it private to prevent access from outside the declaring (enclosing) class. You declare it final to prevent it being extended.
Strictly speaking, the 'final' is redundant, because being private, the class can only be extended within the enclosing class, and if you're editing the enclosing class, you could change the declaration anyway. But it may be a 'declaration of intent', a form of inline documentation that says to other coders, 'leave this class alone'. At the least, it ought to make someone think carefully before changing it.
On the other hand, the author may have thought that knowing the class can't be extended might allow less smart compilers to make more efficient code...
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.