Skip to content

Instantly share code, notes, and snippets.

@caiiiycuk
Created July 24, 2013 03:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caiiiycuk/6067927 to your computer and use it in GitHub Desktop.
Save caiiiycuk/6067927 to your computer and use it in GitHub Desktop.
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