I have the following cake pattern:
// The framework
trait Frame[R] {
def renderer:ReadRender[R]
trait ReadRender[R] { // <<<--- error
def say[T](src:R) : T
}
}
// A specific implementation
trait StringFrame extends Frame[String] {
def renderer = new StringReadRender()
class StringReadRender() extends ReadRender[String] {
def say[T](src:String) : T = {
println("Say: "+src)
null.asInstanceOf[T] // placeholder--actual work here in real code
}
}
}
// Wiring it up
trait SJ[R] {
this : Frame[R] =>
def foo[T](me:R) = {
println("In foo")
renderer.say[T](me)
}
}
case class Greg() extends SJ[String] with StringFrame
With default compiler settings this compiles clean and seems to work. If I enable -Xlint I get this error on the marked line above:
type parameter R defined in trait ReadRender shadows type R defined in trait ReadRenderFrame. You may want to rename your type parameter, or possibly remove it.
This pattern is designed for a JSON parser to allow a mixin trait for injection supporting different types of source data--string default but could be a byte stream or Map.
I'm worried its complaining with the -Xlint scrutiny turned on--and it makes me wonder if what seems to work without -Xlint is really safe or if I just need to be more specific somehow?
Aucun commentaire:
Enregistrer un commentaire