I'm learning scala and created a foo bar code to play around with traits and Manifest. Here's the usage I'm aiming for:
slang = new Slang()
slang.speak[MilitarySlang]("Private")
slang.speak[GanstaSlang]("Homie")
Here's my code:
trait Foo {
val foo = "Foo'd Up "
trait Style {
def phrase(subject : String): String
}
def speak(someone: String): String
}
class Slang extends Foo {
class MilitarySlang extends Style {
def phrase(subject: String) = "Beyond All Recognition, " + subject
}
class GanstaSlang extends Style {
def phrase(subject: String) = "Fo Sheezy, " + subject
}
def speak[Foo with Style: Manifest](someone: String): String = {
val mbar = manifest[Foo with Style].erasure.newInstance().asInstanceOf[Foo with Style]
foo + mbar.phrase(someone)
}
}
Current error I get is with speak[Foo *with Style]
Error ']' expected but 'with' found.
How do I ensure that the type inferred with a class that MUST EXTEND Foo with Style?