Convenience Init Override

后端 未结 1 586
星月不相逢
星月不相逢 2021-01-03 23:55

Problem

Override a convenience initializer of a subclass and it produces a compile error.

Detail

I am

相关标签:
1条回答
  • 2021-01-04 00:36

    The reason override is unneeded:

    Conversely, if you write a subclass initializer that matches a superclass convenience initializer, that superclass convenience initializer can never be called directly by your subclass, as per the rules described above in Initializer Chaining. Therefore, your subclass is not (strictly speaking) providing an override of the superclass initializer. As a result, you do not write the override modifier when providing a matching implementation of a superclass convenience initializer.

    But as written, it seems it should work — as far as I can tell this is a compiler bug. If you change the name of the array argument to ClassB's initializer to e.g. array2, then it works as expected. You should file a Radar!

    0 讨论(0)
提交回复
热议问题