scala - def 中的递归 LazyList 构造给出错误
问题描述
如果我写以下一切都按预期工作:
object Working extends App {
val whl: LazyList[Int] = 1 #:: 2 #:: 3 #:: whl
(1 to 10) foreach {n => println(whl(n)) }
}
但是,如果我将我的包装LazyList
在def
:
object NotWorking extends App {
def f(): Unit = {
val whl: LazyList[Int] = 1 #:: 2 #:: 3 #:: whl
(1 to 10) foreach {n => println(whl(n)) }
}
f()
}
然后我收到一条错误消息
forward reference extends over definition of value whl val whl: LazyList[Int] = 1 #:: 2 #:: 3 #:: whl
有谁知道为什么会这样?我正在使用带有 IntelliJ Idea 的 Scala 2.13.5,如果这有什么不同的话。
解决方案
推荐阅读
- byte - WebAuthn - “凭证公钥”的字节长度
- c++ - 模板参数中未评估 static_assert
- c++ - 指向 const 指针的 C++ 指针
- uwp - UWP:如果缩放因子大于 1,SCrollViewer.ChangeView 不会滚动
- chocolatey - choco install 或 choco upgrade 使用不同的安装参数,无需重新下载
- ms-access - 如何将多行中的值连接到一个文本框(或一个字符串)中
- c++ - 模板更喜欢子类函数而不是更专业的继承函数
- delphi - 按钮执行时 FMX 更新控制
- oauth-2.0 - 如何从不和谐的oauth获取用户ID
- sql-server - SQL Server 条件联接