为什么不推荐使用 Scala 的 Addable?

为什么不推荐使用 Scala 的 Addable?

问题描述:

我注意到 Addable 已弃用,而 Subtractable 不是.Addable 有什么问题,为什么 Subtractable 不同?

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

问题在于 + 被重载以将 String 连接到非字符串.因此,每当您在没有它的类型上使用 + 方法时,您都会收到一条与实际问题无关的错误消息:您拥有的类型不是你所期望的.

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.