Does it make a difference to mark methods as public
in package-private classes?
class SomePackagePrivateClass
{
void foo(); // pack
It makes very little difference, unless the class is extended by a public (or protected nested) class.
As a matter of consistency, I'd go for public
. It should be rare for methods to be anything other than public
or private
.
There are a number of examples of public methods in the package private java.lang.AbstractStringBuilder
class. For instance length()
is public in AbstractStringBuilder
and is exposed in the public class StringBuilder
(overridden in StringBuffer
to add synchronisation).