Seq[T] 和 T* 在 Scala 中是否有区别? [英] Is there a difference in Scala between Seq[T] and T*?

查看:56
本文介绍了Seq[T] 和 T* 在 Scala 中是否有区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 IDE 工具显示 xs 在以下代码段中具有 Int* 类型:

def accept(xs: Int*) = true

然而,语言参考说声明为 T* 的重复参数具有 Seq[T] 类型.Int*Seq[Int] 有区别吗?

解决方案

它们是不同的,它介于 bug 和令人遗憾的特性之间,T* 泄漏到类型签名中.

重复参数输入为 T* 而不是 Seq[T]

My IDE's tooling shows that xs has type Int* in the following snippet:

def accept(xs: Int*) = true

The language reference, however, says that a repeated parameter declared as T* has type Seq[T]. Is there a difference between Int* and Seq[Int]?

解决方案

They are different, and it's somewhere between bug and regrettable feature that T* leaks into type signatures.

Repeated parameter typed as T* rather than Seq[T]

这篇关于Seq[T] 和 T* 在 Scala 中是否有区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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