![](/img/trans.png)
[英]example of using scala.collection.immutable.Set from java
[英]Scala difference between (1 to 4).toSet and (1 to 4).to[scala.collection.immutable.Set]?
(1 to 4).toSet
(1 to 4).to[scala.collection.immutable.Set]
與(1 to 4).toSet
之間的Scala差異?
scala> (1 to 4).toSet
res37: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4)
scala> (1 to 4).to[scala.collection.immutable.Set]
res38: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4)
scala> (1 to 4).to[Set]
res39: Set[Int] = Set(1, 2, 3, 4)
scala> Set(1 to 4:_*)
res14: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4)
它們應該都相同, Set
只是這樣的別名
type Set[A] = immutable.Set[A]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.