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