Skip to content

Instantly share code, notes, and snippets.

@SohumB
Created January 28, 2016 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SohumB/49da049fd69a7331ece0 to your computer and use it in GitHub Desktop.
Save SohumB/49da049fd69a7331ece0 to your computer and use it in GitHub Desktop.
import scala.reflect.runtime.universe.{TypeTag, typeOf}
trait Foo[T]
class Baz extends Foo[String]
def foo[T <: String:TypeTag]: Class[_ <: Foo[T]] = typeOf[T] match {
case t if t =:= typeOf[String] => classOf[Baz]
}
// [error] ...: type mismatch;
// [error] found : Class[Baz](classOf[Baz])
// [error] required: Class[? <: Foo[T]]
// [error] Note: Baz >: ? <: Foo[T], but Java-defined class Class is invariant in type T.
// [error] You may wish to investigate a wildcard type such as `_ >: ? <: Foo[T]`. (SLS 3.2.10)
// [error] case t if t =:= typeOf[String] => classOf[Baz]
// [error] ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment