【发布时间】:2019-03-09 01:17:28
【问题描述】:
具有面向对象编程的背景,我无法理解如何在 Scala 中制作不可变列表。
示例;我想列出 10 个随机的人:
object MyApplication extends App {
val numberOfPersons = 10 : Int
val listOfPersons = makeListOfPersons(numberOfPersons) : List[Person]
def makeListOfPersons( numberOfPersons : Int ) : List[Person] = {
// TODO: return a immutable list of 10 persons
}
}
class Person {
/**
Generic content,
like age and name.
* */
}
在 Scala 中创建不可变列表的“正确”方法是什么?
【问题讨论】:
标签: scala function dictionary recursion