Hello, please explain why someone would declare such an inner class?
and especially why final if its a private class?
Thanks
Printable View
Hello, please explain why someone would declare such an inner class?
and especially why final if its a private class?
Thanks
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...