Search code examples
vala

Undefined types in vala


In Vala, is it possible to declare a function like this

void do_something(object foo) { }

where object stands for any possible type, so that I can for example pass both an integer and a string to this function?

do_something("Foo Bar");
do_something(1234);

Solution

  • You can use a generic if you wanted:

    void do_something<T>(T foo) {}
    

    But what are you going to do with a value you can't use?

    If you want to store it for later reconstitution, you can use a GLib.Value which will be automatically packed by the compiler:

    void do_something(Value foo) {}