[Vala] How to initialize static field


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"));


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]