我注意到这一点:
val word = "My word"
println(word.substring(0,1000))
在 Scala Fiddle 中工作得很好:here
但是在生产环境中运行时它会抛出 ArrayIndexOutOfBounds 异常。为什么 Fiddle 允许这样做,它是 Scala 版本控制吗?我正在 Scala 2.12 中针对我的生产代码对此进行测试。
最佳答案
看起来像是 JVM 与 JS 的区别。请参阅 http://www.scala-js.org/doc/semantics.html 的“未定义行为”部分; ArrayIndexOutOfBoundsException 和 StringIndexOutOfBoundsException 均已列出。
关于Scala substring(i, outOfBoundsNum) 有时在 Fiddle 中可以,但在生产代码中不行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48215630/