Skip to content

Instantly share code, notes, and snippets.

@hubertp
Created March 2, 2012 15:59
Show Gist options
  • Save hubertp/1959320 to your computer and use it in GitHub Desktop.
Save hubertp/1959320 to your computer and use it in GitHub Desktop.
experimenting with manifests
abstract class Foo {
type T
implicit val m: Manifest[T]
def v: T
def prev: Foo
}
case class A(a: Int, prev: Foo) extends Foo {
type T = Int
implicit val m = manifest[Int]
def v = a
}
case class B(a: String, prev: Foo) extends Foo {
type T = String
implicit val m = manifest[String]
def v = a
}
object Test {
def foo[T](elem: Foo)(implicit m: Manifest[elem.T]) {
println("M: " + m)
}
def bar(elem: Foo)(implicit k: Manifest[elem.T]) {
var e = elem
while (e != null) {
val z = e
import z._
println(" TEST " + manifest[z.T] + " vs " + k + " " + z.m)
e = e.prev
}
}
def main(args: Array[String]) {
foo(A(1, null))
foo(A(1, null))(manifest[Int])
val chain = A(1, B("a", A(2, B("b", null))))
bar(chain)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment