overloading + and += operators for “Number Classes”

前端 未结 4 2216
故里飘歌
故里飘歌 2021-02-08 14:41

I want to create extension functions for classes that encapsulate simple Numbers. For example DoubleProperty. I encountered the problem, that I can\'t

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-08 15:27

    You cannot overload both + and +=. Overload one of the them.

    When you write += in your code, theoretically both plus the plusAssign functions can be called (see figure 7.2). If this is the case, and both functions are defined and applicable, the compiler reports an error.

    I copied/pasted from Kotlin in Action book!

提交回复
热议问题