Guest User

Untitled

a guest
May 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.40 KB | None | 0 0
  1. sealed abstract class LogRow
  2. case class TypeARow(x: String, y: Int) extends LogRow
  3. case class TypeBRow(y: String, z: Double) extends LogRow
  4.  
  5. // Here comes the factory
  6. object LogRow {
  7.   def apply[T <: LogRow : ClassManifest](s: String): T = classManifest[T] match {
  8.     case x: TypeARow => new TypeARow("xpto", 1).asInstanceOf[T]
  9.     case x: TypeBRow => new TypeBRow("xpto", 0.5).asInstanceOf[T]
  10.   }
  11. }
Add Comment
Please, Sign In to add comment