Why doesn't Java allow overriding of static methods?

后端 未结 22 3205
谎友^
谎友^ 2020-11-21 05:49

Why is it not possible to override static methods?

If possible, please use an example.

22条回答
  •  庸人自扰
    2020-11-21 06:30

    I like and double Jay's comment (https://stackoverflow.com/a/2223803/1517187).
    I agree that this is the bad design of Java.
    Many other languages support overriding static methods, as we see in previous comments. I feel Jay has also come to Java from Delphi like me.
    Delphi (Object Pascal) was one of the languages implementing OOP before Java and one of the first languages used for commercial application development.
    It is obvious that many people had experience with that language since it was in the past the only language to write commercial GUI products. And - yes, we could in Delphi override static methods. Actually, static methods in Delphi are called "class methods", while Delphi had the different concept of "Delphi static methods" which were methods with early binding. To override methods you had to use late binding, declare "virtual" directive. So it was very convenient and intuitive and I would expect this in Java.

提交回复
热议问题