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]
}
我如何在运行时投射?
答案 0 :(得分:0)
我们可以使用下面的反射
Class.forName(“完全限定的类名”)。newInstance()