I'm reading through docs and trying to understand what Scala traits and objects and all these fun things are, but still unable to figure out how to resolve this problem.
sealed trait MyTrait {
val username: Option[String]
val password: Option[String]
}
sealed trait OptionTrait{
val types: Option[Types]
}
case class Types(
col: String
)
case class MyTraitTypes(
user: String
password: String
)
case class MyClass (
auth: Option[MyTraitTypes]
type: Option[Types]
) extends AnotherClass with OptionTrait with MyTrait
The error is on MyClass
, where it wants Class must either be declared abstract or implement abstract member password: Option[String]
in MyTrait`. Any help please?
-----edit
so my confusion is that OptionTrait
works just fine. I can't distinguish the difference between these two (the working one vs non-working one). Because it doesn't seem like that class Types
is doing anything either.
There should not be comma after username
. Also auth
should be in parentheses rather than braces.
Try
class AnotherClass
sealed trait MyTrait {
val username: Option[String]
val password: Option[String]
}
case class MyClass(
auth: Option[MyTrait]
) extends AnotherClass with MyTrait {
override val username: Option[String] = ???
override val password: Option[String] = ???
}
where you are supposed to implement methods instead of ???
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.