-1

I don't understand, i look the code of WindowManager.java and i can see :

public interface WindowManager extends ViewManager {

    public static class LayoutParams extends ViewGroup.LayoutParams
            implements Parcelable {

        /**
         * Control flags that are private to the platform.
         * @hide
         */
        public int privateFlags;

        /**
         *
         * @see Gravity
         */
        public int gravity; 

     }
}

Why i can access the field gravity but can't access the field privateFlags ? The declaration of both fields seem similar so why i can't ?

zeus
  • 12,173
  • 9
  • 63
  • 184
  • I'm going to go out on a limb here and say that you can in fact access `privateflags`. What's stopping you? – Carcigenicate Sep 24 '16 at 11:54
  • @GiantTree From what I just read, `@hide` only prevents documentation from being generated, it doesn't effect your ability to programatically access a field. – Carcigenicate Sep 24 '16 at 11:59
  • @GiantTree Oh, maybe not. The OP in the link seems to be getting an error when accessing, but the answers mostly just state that it effects documentation generation. – Carcigenicate Sep 24 '16 at 12:00
  • @Carcigenicate You can only access that field through reflection. Also: There should be no need to access a hidden field, like the answers suggest. – GiantTree Sep 24 '16 at 12:01
  • @GiantTree I know there shouldn't be any need to access it, it's effectively private to anyone using the API. I'm just confused that the OP in the link is getting an error, but the answers suggest that it only effects documentation generation. – Carcigenicate Sep 24 '16 at 12:03
  • Look [here](http://stackoverflow.com/questions/31908205/what-exactly-does-androids-hide-annotation-do) (also linked in the answer). The compiler cannot compile the app because the library is stripped from those fields, meaning that they are not there at compile-time, but at runtime they are there. – GiantTree Sep 24 '16 at 12:04
  • thanks everyone, no i can't access the privateflags, when i try i receive error: cannot find symbol :( via reflection yes of course i can ... – zeus Sep 24 '16 at 14:31

1 Answers1

0

The fact that you call your field "privateFlag" doesn't mean you can't access. You can access to the field because is public.

In java access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:

  • At the top level—public, or package-private (no explicit modifier).
  • At the member level—public, private, protected, or package-private (no explicit modifier).

For more read here.


For what concerns the @hide attribute (in Android),

it is just part of javadoc(droiddoc also), so the @hide just simply mean the method/class/field is excluded from the API docs.

For more read here and here.

Community
  • 1
  • 1
granmirupa
  • 2,780
  • 16
  • 27
  • not only exclude from the doc, because when i compile i receive: error: cannot find symbol :( – zeus Sep 24 '16 at 14:30