Android Source Code Style

之前在看 Android 的 Source Code 時,

看到變數前面都會加個 m ,

以為很潮就跟著學起來,

其實根本不知其所以然,

直到今天在 Android Source Code 文件看到解說才知道,

原來 Android Source Code 遵守以下的規範:

  • 非 Public、static 變數名稱開頭加 m
  • static 變數開頭加 s
  • 其他變數使用小寫字母開頭
  • Public static final 變數使用大寫字母
範例
public class MyClass {
    public static final int SOME_CONSTANT = 42;
    public int publicField;
    private static MyClass sSingleton;
    int mPackagePrivate;
    private int mPrivate;
    protected int mProtected;
}

來源

Comments

comments powered by Disqus