Skip to content

Instantly share code, notes, and snippets.

@jrudolph
Created October 25, 2014 09:36
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 jrudolph/cfa1cbce46c3d7cb4d92 to your computer and use it in GitHub Desktop.
Save jrudolph/cfa1cbce46c3d7cb4d92 to your computer and use it in GitHub Desktop.
Getting return types of methods without actually calling them
import scala.reflect.{ classTag, ClassTag }
trait X {
def f: Seq[Int]
}
trait Getter[T] {
def apply[U: ClassTag, C[_]](f: T ⇒ C[U]): ClassTag[U] = implicitly[ClassTag[U]]
}
object Getter extends Getter[Any]
def memberClassTagFrom[T]: Getter[T] = Getter.asInstanceOf[Getter[T]]
println(memberClassTagFrom[X](_.f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment