Java convention on reference to methods and variables

前端 未结 6 1098
一个人的身影
一个人的身影 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:11

    It is only because, public static method or public static variable is not associated with any object, but the class. Though the language designer has given the flexibility of invoking them on objects, reader of the code would be confused whether those are static variable/methods or instance methods/variables. So readability is the reason behind asking the developers to invoke them on classes.

提交回复
热议问题