Skip to content

Instantly share code, notes, and snippets.

@yangbajing
Created October 24, 2012 09:46
Show Gist options
  • Save yangbajing/3945180 to your computer and use it in GitHub Desktop.
Save yangbajing/3945180 to your computer and use it in GitHub Desktop.
Manifest
class MakeFoo[A](implicit manifest: Manifest[A]) {
def make: A = manifest.erasure.newInstance.asInstanceOf[A]
private def test {
val r = scala.math.random
}
}
scala> new MakeFoo[java.util.Date]
res1: MakeFoo[java.util.Date] = MakeFoo@18ca1436
scala> res1.make
res2: java.util.Date = Wed Oct 24 17:47:53 CST 2012
scala> res1.make
res3: java.util.Date = Wed Oct 24 17:47:56 CST 2012
scala> res1.make
res4: java.util.Date = Wed Oct 24 17:47:57 CST 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment