寫出一個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`
}
}
如何確保它不會返回一個單位?
+1用於顯示多種語法;) – crockpotveggies