隐藏静态方法vs覆盖非静态方法

时间:2016-05-17 10:56:33

标签: java

使用静态方法不会利用OOP,因此方法被覆盖,而不是隐藏。然而,Java中存在隐藏静态方法的问题。只是在一些无望的情况下帮助吗?
隐藏静态方法与重写非静态方法有什么后果?是否有任何情况下隐藏应优先于覆盖(直到使方法静态,这通常取决于其他优点)?

1 个答案:

答案 0 :(得分:2)

Java is an object-oriented programming language such that you should always prefer an OO approach from a pure procedural approach, in other words you should always prefer to override a method rather than hiding a static method. I would even say that hiding a static method is a terrible approach because it is very error prone, you should alway prefix a call to a static method with the name of the corresponding class