3
,你可以做斯卡拉下列事实是很整齐:我该如何参考一个在Scala中没有实际意义的类?
scala> class FooBar
defined class FooBar
scala> val a = new FooBar
a: FooBar = [email protected]
scala> val the_class = a.getClass
the_class: java.lang.Class[_ <: FooBar] = class FooBar
scala> val b = the_class.newInstance
b: FooBar = [email protected]
假设我要直接设置的the_class
值。我似乎能够申报正确类型的变量:
scala> var the_class: java.lang.Class[_ <: FooBar] = null
the_class: java.lang.Class[_ <: FooBar] = null
但我似乎并没有能够将变量绑定到任何价值。这可能吗?
scala> the_class = class FooBar
<console>:1: error: illegal start of simple expression
the_class = class FooBar
^
scala> the_class = FooBar
<console>:9: error: not found: value FooBar
the_class = FooBar
^
是的!不知道我错过了这个。谢谢。 – 2012-03-07 20:54:02