Why is Scala's Addable deprecated?

后端 未结 2 1753
天涯浪人
天涯浪人 2021-02-18 23:30

I noticed that Addable is deprecated, while Subtractable is not. What\'s wrong with Addable, and why is Subtractable different?

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-19 00:10

    The problem is that + is overloaded to concatenate String to non-strings. So, whenever you use the + method on a type that doesn't have it, you'll get an error message that is not related to the real problem: that the type you have isn't the one you expected.

    There's +: and :+ to replace it.

提交回复
热议问题