[Vala] How to initialize static field
- From: Pavel Stupnikov <dp dpointer org>
- To: vala-list gnome org
- Subject: [Vala] How to initialize static field
- Date: Fri, 13 Nov 2009 02:58:20 +0300
Hello!
I want to create some static fields. Int field works ok, but HashMap
remains null even after initialization... What i did wrong?
using Gee;
public static class Foo: Object {
public static HashMap<string, int> bar = new HashMap<string, int>();
public static int a = 5;
}
void main () {
stdout.printf("a = %d\n",Foo.a);
stdout.printf("bar: %s\n",(Foo.bar==null?"null":"ok"));
}
prints
a = 5
bar: null
P.S. Same code on mono works fine:
using System;
using System.Collections;
public static class Foo {
public static Hashtable bar = new Hashtable();
public static int a = 5;
}
class HelloCsharp {
public static void Main() {
Console.WriteLine("a = "+Foo.a.ToString());
Console.WriteLine("bar: "+Foo.bar.ToString());
}
}
a = 5
bar: System.Collections.Hashtable
-- Pavel Stupnikov
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]