我有以下类型
class Translator[To <: Language] { ... }
abstract class Language
object English extends Language
object German extends Language
有没有办法Translator
从val
typeEnglish
或实例化German
?
我正在寻找类似以下的东西(不起作用):
val lang = if (someCondition) English else German
val translator = new Translator[classOf[lang]]