Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.test
- import scala.reflect._
- class Test()(implicit m: Manifest[Int]) {
- private val BooleanCls = classOf[Boolean]
- private val IntCls = classOf[Int]
- private val LongCls = classOf[Long]
- private val FloatCls = classOf[Float]
- private val DoubleCls = classOf[Double]
- private val StringCls = classOf[String]
- def maybeSet[T: ClassTag](setter: T => Any, value: String, name: String) {
- val v = value + name
- val t = classTag[T].runtimeClass match {
- case BooleanCls => v.toBoolean
- case IntCls => v.toInt
- case LongCls => v.toLong
- case FloatCls => v.toFloat
- case DoubleCls => v.toDouble
- case StringCls => v
- }
- setter(t.asInstanceOf[T])
- }
- }
- object Main extends App {
- new Test().maybeSet[Int](setBlah, "123", "000")
- def setBlah(i: Int): Unit = {
- println("blah")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement