我正在尝试使用条件语句覆盖 toString。但是我收到一个错误,指出类型不匹配。它应该是 String 类型,现在它是 Any 类型。noGoals、Tied 是返回 true 或 false 的函数。
override def toString = {
if (this.noGoals)
s"${this.home} vs. ${this.away} at ${this.location}: no goals"
else if (this.Tied)
s"${this.home} vs. ${this.away} at ${this.location}: tied"
}
Run Code Online (Sandbox Code Playgroud)