java.lang.ClassCastException:java.lang.String无法强制转换为com.fastdata.persistence.PersistenceService

时间:2017-01-31 11:03:33

标签: scala

trait PersistenceService  {
    def setData(x: Any): Unit
    def getData(x:Any) : Any
}

object ConfigurationLoader{
    var p_service: PersistenceService = null
    val persistence_db = component_props.getProperty("persistence_db")
    p_service = (persistence_db+"Service").asInstanceOf[PersistenceService]
}

我如何在运行时投射?

1 个答案:

答案 0 :(得分:0)

我们可以使用下面的反射

Class.forName(“完全限定的类名”)。newInstance()