I'm quite new to Scala, but I'm trying to implement the following situation. Suppose I have a trait:
trait SomeTrait {
def kakaw
}
And two Scala objects that extend it:
object SampleA extends SomeTrait {
def kakaw = "Woof"
}
object SampleB extends SomeTrait {
def kakaw = "Meow"
}
What I'd like to do is call one of these two object functions based on a parameterized function call. For example (and I know this is the furthest thing from correct):
class SomeOther {
def saySomething[T] = T.kakaw
}
So I can do something like:
val s = new SomeOther
s.saySomething[SampleA]
Is this at all possible in Scala?
def saySomething(t: SomeTrait) = t.kakawand thens.saySomething(SampleA)? That is, why bother with the type parameter at all?SampleAis not a type, so you cannot pass it as a type parameter.