Obviously Java has a Access level package-private which achieved by not adding any explicit modifier.
But isn't there a way to explicitly add this modifier? It's a bit confusing that we need to omit access level when we want to use member in package only.
If there's no way, why package private decided to be a default level?
For example if default level was public than we would more consciously define relevant access level.
This isn't duplicate of question of why use it, because I know why, I just don't know why it's define implicitly and can't be defined explicitly.
EDIT
You can define it explicitly by using Lombok's @PackagePrivate
Used to indicate the explicit intention for the annotated entity to have the package private access level. Currently used by FieldDefaults and Value to avoid having it make a field one of public, protected, or private.
@PackagePrivate String thanksLombok;
no explicit modifier
meansno
– Throbpublic
than we would more consciously define relevant access level" I don't follow. Why would a default ofpublic
do that? You always have to consciously decide on access level, by either writing a keyword, or not. Not writing a keyword is still a conscious decision. – Margravineprotected
is similar but it will leak access to sub-classes in other packages. I too would have chosen package-private to be the default because of this reason. – Bohnerpublic
is certainly wrong. – Margravine@VisibleForTesting
, a little different purpose, but the idea is around that too – Delija