2017-03-10 72 views

回答

5

它看起来像Range的toString函数已在Scala 2.12中更改。

测试与2.12.0

scala> (1 to 10) 
res0: scala.collection.immutable.Range.Inclusive = Range 1 to 10 

测试与2.11.8

scala> (0 to 10) 
res0: scala.collection.immutable.Range.Inclusive = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 

Source code for 2.12

override def toString = { 
    val preposition = if (isInclusive) "to" else "until" 
    val stepped = if (step == 1) "" else s" by $step" 
    val prefix = if (isEmpty) "empty " else if (!isExact) "inexact " else "" 
    s"${prefix}Range $start $preposition $end$stepped" 
} 

Source code for 2.11

override def toString() = { 
    val endStr = 
    if (numRangeElements > Range.MAX_PRINT || (!isEmpty && numRangeElements < 0)) ", ...)" else ")" 
    take(Range.MAX_PRINT).mkString("Range(", ", ", endStr) 
} 

+0

但用来显示的数字,不是吗?那个改变了吗? – nmat

+0

编辑我的答案,以反映问题 – Tyler

+0

是啊,看起来它已经从2.12更改。谢谢!! –