The fact that you can do the following in Scala is pretty neat:
scala> class FooBar
defined class FooBar
scala> val a = new FooBar
a: FooBar = FooBar@7efeedca
scala> val the_class = a.getClass
the_class: java.lang.Class[_ <: FooBar] = class FooBar
scala> val b = the_class.newInstance
b: FooBar = FooBar@1ef1df56
Suppose I want to set the value of the_class directly. I appear to be able to declare a variable of the correct type:
scala> var the_class: java.lang.Class[_ <: FooBar] = null
the_class: java.lang.Class[_ <: FooBar] = null
But I don't appear to be able to bind the variable to any value. Is this possible?
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
^
Did you mean:
val the_class = classOf[FooBar]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With