Skip to content

Instantly share code, notes, and snippets.

@tindzk
Created February 15, 2015 15:53
Show Gist options
  • Save tindzk/cb13b726ef97e84ff5bb to your computer and use it in GitHub Desktop.
Save tindzk/cb13b726ef97e84ff5bb to your computer and use it in GitHub Desktop.
Type mismatch when casting generic parameter to an existential type
trait A[T] { def print(t: T) }
trait B[T] { def ret: T }
case class Wrapper[T](a: A[T], b: B[T])
val wrapper = Wrapper[String](null, null)
wrapper.a.print(wrapper.b.ret) /* Compiles */
val anyWrapper = wrapper.asInstanceOf[Wrapper[_]]
anyWrapper.a.print(wrapper.b.ret) /* Does not compile */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment