Re: [Vala] static string variable is empty!



Jan Hudec wrote:

On Tue, January 5, 2010 13:12, Frederik wrote:
You have several options:

- create a throw-away instance:

  static int main (string[] args) {
      new Global ();
      stdout.printf ("all data is in: " + Global.dataDir);
      return 0;
  }

Actually, there is no need to do that -- calling typeof(Global); is enough.

No, I have tried that. I thought so, too, but it doesn't work.

- call a static initialization method:

  static int main (string[] args) {
      Global.init ();
      stdout.printf ("all data is in: " + Global.dataDir);
      return 0;
  }

This should not work. *static* methods do not cause a class to be
initialized (*class* methods do, though).

I was under the impression that class methods are called 'static'
methods in Vala/Java/C#.

- make 'dataDir' const, if it is not intended to change

- make the variable a class one instead of static one.

public class Global {
    class string dataDir = "whatever";
}


This does not compile.


Best regards,

Frederik



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]