android - Java package-private visibility members with /*package*/ suffix -


even if don't find often, what's reason of comment /* package*/ before members?

 /* package */ final void attach(context context) {     attachbasecontext(context);     mloadedapk = contextimpl.getimpl(context).mpackageinfo; } 

here example aosp line 180: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/app/application.java

by default, members in java use package-level access - can accessed other classes in same package, not classes in other packages.

actually using functionality rare, since want of variables private (or protected), , methods either private (for self-use), protected, or public.

there no explicit "package" modifier, there's no easy way know @ glance if modifier missing because author forgot include correct one, or because intentionally wanted member have package-level access.

that's why, in rare cases when want use package, it's practice put /* package */ comment in front of method declaration, state intentionally using access level, rather accidentally forgetting specify one.

the comment doesn't far compiler concerned - makes code easier understand.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -