Why is it preferable to call a static method statically from within an instance of the method's class?

前端 未结 5 1525
自闭症患者
自闭症患者 2021-01-13 10:16

If I create an instance of a class in Java, why is it preferable to call a static method of that same class statically, rather than using this.method()?

I get a warn

5条回答
  •  渐次进展
    2021-01-13 10:40

    Static methods are not tied to an instance of the class, so it makes less sense to call it from a this than to call it from Class.staticMethod(), much more readable too.

提交回复
热议问题