Created
June 12, 2019 06:31
-
-
Save ruslanbogun/38268ca7352ed3856e16fb5ad3abe46c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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