public methods in package-private classes

后端 未结 7 1649
刺人心
刺人心 2020-12-04 19:35

Does it make a difference to mark methods as public in package-private classes?

class SomePackagePrivateClass
{
    void foo();          // pack         


        
7条回答
  •  情书的邮戳
    2020-12-04 19:49

    If the class is not going to be extended by another, more visible subclass*, the only difference is clarity of intent. Declaring all methods package private makes it more difficult for future readers to determine which of the methods are meant to be called by other classes in the same package.

    *which would not make much sense as a design solution to me, but technically is possible nevertheless.

提交回复
热议问题