Guest User

Untitled

a guest
Aug 25th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.46 KB | None | 0 0
  1. import scala.reflect.runtime.universe._
  2.  
  3. case class B[T](thing: Option[T])
  4.  
  5. object Factory {
  6.   def get: B[_] = B(Some(0))
  7. }
  8.  
  9. class Blah {
  10.   // Type info lost here
  11.   val someB = Factory.get
  12. }
  13.  
  14. def checkType[T: TypeTag](in: T) = {
  15.   println(typeOf[T])
  16.  
  17.   typeOf[T] match {
  18.     case o if o =:= typeOf[Option[Int]] => "hit!!"
  19.   }
  20. }
  21.  
  22. def process(in: Blah) = {
  23.   in.someB match {
  24.     case b: B[_] => checkType(b.thing)
  25.   }
  26. }
  27.  
  28. process(new Blah)
Add Comment
Please, Sign In to add comment