GNOME Bugzilla – Bug 621944
construct does not invoke before accessing static member
Last modified: 2010-06-19 10:01:49 UTC
I know that the documentation states that static construct happens before the first instantiation of the class. But you can't really use it to initialize static members because they might be accessed before the first instantiation. the singleton design pattern is the perfect example where it could have bee useful to use a static struct but is impossible. Take this example: class Singleton : Object { public Singleton instance {get; private set;} static construct { instance = Singleton(); } private Singleton() {}; } void main(){ var singleton = Singleton.instance; } This doesn't work because construct never happens. I think giving *real* static constructor (initialized before main or on first access to any member of class or derived classes) is an important feature and also the current behavior is a bit confusing.
Looks the same as bug 543189
It is, sorry about that. Marking as duplicate *** This bug has been marked as a duplicate of bug 543189 ***