In Scala, I can declare an object like so:
class Thing
object Thingy extends Thing
How would I get "Thingy"
(the name of the object) in Scala?
I've heard that Lift (the web framework for Scala) is capable of this.
In Scala, I can declare an object like so:
class Thing
object Thingy extends Thing
How would I get "Thingy"
(the name of the object) in Scala?
I've heard that Lift (the web framework for Scala) is capable of this.
I don't know which way is the proper way, but this could be achieved by Scala reflection:
If you declare it as a
case object
rather than just anobject
then it'll automatically extend theProduct
trait and you can call theproductPrefix
method to get the object's name:Just get the class object and then its name.
All that's left is to remove the
$
.EDIT:
To remove names of enclosing objects and the tailing
$
it is sufficient to do