Skip to content

Instantly share code, notes, and snippets.

@caiiiycuk

caiiiycuk/XitrumTest

Created Jul 24, 2013
Embed
What would you like to do?
Scala bug SI-6240
import scala.reflect.runtime.universe._
object ParamAccess {
val typeString = typeOf[String]
}
class ParamAccess {
import ParamAccess._
def paramo[T: TypeTag](key: String, coll: Map[String, Seq[String]]): Option[T] = {
val values = coll.get(key)
val valueo = values.map(_(0))
valueo.map(convertText[T](_))
}
def convertText[T: TypeTag](value: String): T = {
val t = typeOf[T]
val any: Any =
if (t <:< typeString) value
else throw new Exception("Cannot covert " + value + " to " + t)
any.asInstanceOf[T]
}
}
class Test extends Runnable() {
def run() {
val access = new ParamAccess()
val value = access.paramo[String]("test", Map("test" -> Seq("value")))
println("Parsed: " + value)
}
}
object XitrumTest {
def main(args: Array[String]): Unit = {
println("Hello world\n")
for (i <- 1 to 10) {
new Thread(new Test()).start()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.