Hi, I don't know if a solution exists but it would be highly desirable.
I'm making a Scala Applet, and I want the main Applet class to be a singleton so it can be accessed elsewhere in the applet, sort of like:
object App extends Applet {
def init {
// do init here
}
}
Instead I have to make the App class a normal instantiatable class otherwise it complains because the contructor is private. So the ugly hack I have is to go:
object A {
var pp: App = null
}
class App extends Applet {
A.pp = this
def init {
// do init here
}
}
I really hate this, and is one of the reasons I don't like making applets in Scala right now.
Any better solution? It would be nice...
edit -- I found a pretty decent hack solution using implicit conversion. Declare your Applet class as a normal class, and then add:
class Appable {}
object App extends Appable {
implicit def appable2App(a:Appable) = inst
var inst: App = null
}
Then just set the instance variable when the Applet is created, and you can access everything as if it were a singleton.