我正在编写一个代码,在该代码中我声明了一个“val”类型变量并将其传递给一个递归函数,该函数对其进行了更改:
def calculateDates(from: LocalDate, until: LocalDate, by: RDate, holidays: HolidayCalendar): Seq[LocalDate] =
{
val dateSeq: Seq[LocalDate] = Seq(from)
def calculateDatesRecur(from: LocalDate, dateSeq: Seq[LocalDate]): Seq[LocalDate] =
{
val date = by(from, holidays)
if (date.compareTo(until) <= 0)
calculateDatesRecur(date, dateSeq :+ date)
else
dateSeq
}
calculateDatesRecur(from, dateSeq)
}
'dateSeq' 是一个变量,它最终是从 'from' 到 'until' 的日期列表。好吧,事实证明它有效。应该不对吧?因为“dateSeq”变量已被初始化为“val”。是否将其副本发送到递归函数?