What is the reasoning behind not allowing supertypes on Java method overrides?

前端 未结 7 1604
悲哀的现实
悲哀的现实 2021-01-31 10:23

The following code is considered invalid by the compiler:

class Foo {
    void foo(String foo) { ... }
}

class Bar extends Foo {
    @Override
    void foo(Obje         


        
7条回答
  •  半阙折子戏
    2021-01-31 11:19

    To answer the question in the title of the post What is the reasoning behind not allowing supertypes on Java method overrides?:

    The designers of Java wanted a simple object oriented language and they specifically rejected features of C++ where, in their opinion, the complexity/pitfalls of the feature wasn't worth the benefit. What you describe may have fallen into this category where the designers chose to design/specify out the feature.

提交回复
热议问题