安卓 Java 类构造函数命名惯例

huangapple go评论63阅读模式
英文:

Android java class constructor naming convention

问题

我最近开始进行Android开发(对于JAVA也是新的),想要了解Android Java中的类命名约定。

考虑以下类:
通用类定义在此处

public final class Class

Toast类在此处

Toast toast = Toast.makeText(context, text, duration);

我发现一些示例代码中,类被命名为

Class mClass

在Android Java中,通常遵循什么样的命名约定?

另外,在mClass中,m代表什么意思?

英文:

I recently started Android development(also JAVA is new to me) and would like to know the class naming convention in Android Java.

Considering the following class
General class definition here

public final class Class

Toast class here

Toast toast = Toast.makeText(context, text, duration);

I found some example code where class is named as

Class mClass

What is the commonly followed naming convention in Android Java?

Also what does m stand for in mClass?

答案1

得分: 1

这些是谷歌的实习生命名约定!如果您不想遵循这些约定,也没关系。关于这些约定没有对错之分。

命名约定是在团队中与其他程序员共同工作时需要遵循的。它们是一种用于组织由多个程序员编写的代码的方法。

谷歌的字段命名约定:

  • 非公共、非静态字段名称以字母“m”开头。
  • 静态字段名称以字母“s”开头。
  • 其他字段以小写字母开头。
  • 公共静态常量字段(常量)采用全大写加下划线的形式(ALL_CAPS_WITH_UNDERSCORES)。

基本上每家公司/程序员都有自己命名变量、类等的方式。找到最适合您的方式吧!

英文:

These are Google's intern naming convention! You don't have to follow these, if you don't want to. There is nothing right or wrong about them.
Naming conventions are to follow, when you work together with other programmers in a team. They are a method to structure code, written by multiple programmers.

Google's Field naming convention:

  • Non-public, non-static field names start with 'm'.
  • Static field names start with 's'.
  • Other fields start with a lower case letter.
  • Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES

Basically every company/programmer has there own way to name variables, classes, etc. Find what suites you the best!

huangapple
  • 本文由 发表于 2020年10月8日 19:08:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/64261263.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定