Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ruslanbogun/38268ca7352ed3856e16fb5ad3abe46c to your computer and use it in GitHub Desktop.
Save ruslanbogun/38268ca7352ed3856e16fb5ad3abe46c to your computer and use it in GitHub Desktop.
import scala.reflect._
trait History
case class SlotHistory(t: Int) extends History
case class RouletteHistory(t: String) extends History
def test[T <: History : ClassTag](): T = {
classTag[T].runtimeClass match {
case h if h.isAssignableFrom(classOf[SlotHistory]) ⇒ SlotHistory(1).asInstanceOf[T]
case h if h.isAssignableFrom(classOf[RouletteHistory]) ⇒ RouletteHistory("One").asInstanceOf[T]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment