I'm curious about the name of the Android variable

Asked 2 years ago, Updated 2 years ago, 133 views

LayoutInflater mLayoutInflater;

I have a question while I was looking at Android open source.

Many people put m at the beginning of the variable as above, and I wonder why.

naming-convention android

2022-09-22 10:39

2 Answers

Android open source follows Naming Convention as below.

Follow Field Naming Conventions

//example
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;
}

http://source.android.com/source/code-style.html#follow-field-naming-conventions If you go to the address above, you can see more detailed rules.

The above rules are only for the Android open source project, and you are free to create a personal Android app. When I made the Android app, I followed Java code convention. ;
For your information, the Java code style does not use Hungarian notation.

;;


2022-09-22 10:39

In order to improve readability, when developing a program, there are cases where a special abbreviation is added before the variable name according to the Hungarian nomenclature. It's not a linguistic feature or anything like that, so it doesn't have to be done as above, but depending on the development language or the project development team, you may use different naming conventions, which you can follow.

The prefix m you asked is an abbreviation for member (which means class variable or class member variable).

Usually, write the abbreviation for member(m)/global(g)/static(s) and type in order in the prefix.

For the type , write the following prefixes

For pointers, add a p prefix before the type.


2022-09-22 10:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.