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
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.