2016-09-24 65 views
-1

我不明白,我看WindowManager.java的代码,我可以看到:android java:为什么我可以访问一些公共字段并且无法访问其他?

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; 

    } 
} 

为什么我可以访问现场重力但不能访问现场privateFlags?这两个领域的声明看起来很相似,所以我为什么不能?

+0

我打算在这里出门,说你实际上可以访问'privateflags'。什么东西阻止你? – Carcigenicate

+0

@GiantTree从我刚刚阅读的内容来看,'@ hide'只能防止生成文档,并不会影响您以编程方式访问字段的能力。 – Carcigenicate

+0

@GiantTree哦,也许不是。链接中的OP似乎在访问时出现错误,但答案大多只是说明它会影响文档生成。 – Carcigenicate

回答

0

事实上,您称您的字段为“privateFlag”并不意味着您无法访问。 您可以访问该字段,因为它是公开的。

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).

欲了解更多信息here


对于所关注的@hide属性(在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.

更多阅读herehere

+0

不仅从文档中排除,因为当我编译我收到:错误:找不到符号:( – loki

相关问题