写出一个 Scala 类,这里的问题是编译器认为代码是一个没有返回正确值的单元。这是一种用于在类中设置属性的方法:
def setObject(`object`:StripeObject):StripeObject = {
this.`object` = `object`
}
错误是:type mismatch; found : Unit required: com.stripe.StripeObject
完整的课程是:
case class EventData(var previousAttributes: HashMap[String,Object], var `object`:StripeObject) extends StripeObject {
def getPreviousAttributes = {
previousAttributes
}
def setPreviousAttributes(previousAttributes: HashMap[String, Object]) = {
this.previousAttributes = previousAttributes
}
def getObject = {
`object`
}
def setObject(`object`:StripeObject):StripeObject = {
this.`object` = `object`
}
}
如何确保它不返回单位?