2016-09-24 68 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

相關問題