Java convention on reference to methods and variables

前端 未结 6 1092
一个人的身影
一个人的身影 2021-01-18 16:19

Section 10.2 of Java conventions recommends using class names instead of objects to use static variables or methods, i.e. MyClass.variable1 or MyClass.met

6条回答
  •  离开以前
    2021-01-18 17:03

    This has to do with public static methods and variables. Since these methods/variables are associated with the respective class rather than an instance of the class, it is nice to use refer to these methods or variables as className.methodName() or className.variableName

    "Understanding Instance and Class Members" would be a good starting point to learn about the use of the static keyword to create fields and methods that belong to the class, rather than to an instance of the class

提交回复
热议问题