Why make private inner class member public in Java?

前端 未结 7 1972
情深已故
情深已故 2020-12-02 15:54

What is the reason of declaring a member of a private inner class public in Java if it still can\'t be accessed outside of containing class? Or can it?

publi         


        
相关标签:
7条回答
  • 2020-12-02 16:22

    This method can be made public in order to indicate that it's semantically public, despite the fact that compiler doesn't enforce visibility rules in this particular case.

    Imagine that during some refactoring you need to make this inner class top-level. If this method is private, how would you decide whether it should be made public, or some more restrictive modifier should be used? Declaring method as public tells reader the intentions of original author - this method shouldn't be considered an implementation detail.

    0 讨论(0)
提交回复
热议问题