在Scala中,我有一个案例类:设置格式
case class MonthSelectionInfo(monthSelection: MonthSelection.Value, customMonth:Int = 0, customYear:Int = 0) {
def this(monthSelection: MonthSelection.Value) = {
this(monthSelection, 0, 0)
}
}
object MonthSelection extends Enumeration {
type MonthSelection = Value
val LastMonth, ThisMonth, NextMonth, CustomMonth = Value
}
当我有案件类的实例,我不得不使用
myMonthSelectionInfo.monthSelection
和
myMonthSelectionInfo.eq(newMonthSelection)
得到&设置MonthSelection实例包含在里面。
是否有任何不错的Scala方式来设置getter & setter,使其看起来更像普通的Java POJO?例如
myMonthSelectionInfo.setMonthSelection(newMonthSelection)
请注意,这会产生额外的getter和setter。它不会删除Scala的默认获取者和设置者。 –
完美,谢谢 – Reimeus
不应该大小写不可改变? – Lukasz