Should we declare a public constructor when the class is declared as package private?

前端 未结 2 1080
别跟我提以往
别跟我提以往 2020-12-06 09:49

I think in this case there is no need to declare a public constructor since the class is not accessible outside the package anyway. But is there some hidden impact when the

2条回答
  •  天命终不由人
    2020-12-06 10:15

    No, you don't have to declare the public constructor; package private constructors will be just as usable. Classes outside the package wouldn't be able to use the constructor anyway, since they can't see the class.

提交回复
热议问题