extension function in a kotlin using super

前端 未结 3 1809
后悔当初
后悔当初 2021-01-18 18:06

How to call extension function of the base class in a derived class using the super keyword?

I tried to call using super but it doesn\'t work.

 open         


        
3条回答
  •  囚心锁ツ
    2021-01-18 18:59

    This type of namespace conflict is a general drawback of extension methods. Extension methods are essentially static and do not mix well with inheritance.

    In your particular case, there doesn't seem to be a need for the function sum to be an extension method. If you change it to an open virtual method, you will be able to design better for inheritance and potential overriding in a subclass.

提交回复
热议问题