Reputation: 2393
I have the below trait and I want constants to have more than one type parameter
trait MyTrait[+A] {
val value: A
}
object Currency {
sealed trait MyConstants extends MyTrait[String]
case object A extends MyConstants {val value ="abc"}
//etc.
case object B extends MyConstants {val value = "def"}
//etc.
val list = Seq(A, B)
}
I want to create another case object C extends MyConstants {val value = 10}
Can anyone suggest a way to make a type parameter take Int or String
as types
Upvotes: 1
Views: 180
Reputation: 9698
Why not parameterize MyConstants
itself?
sealed trait MyConstants[T] extends MyTrait[T]
case object A extends MyConstants[String] {val value ="abc"}
case object B extends MyConstants[Int] {val value = 10}
Upvotes: 2