CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: private final class???

  1. #1
    Join Date
    May 2013

    private final class???

    Hello, please explain why someone would declare such an inner class?
    and especially why final if its a private class?


  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)