为什么不推荐使用 Scala 的 Addable? [英] Why is Scala's Addable deprecated?

查看:62
本文介绍了为什么不推荐使用 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.

这篇关于为什么不推荐使用 Scala 的 Addable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆