Re: [Vala] help with java to vala
- From: bsquared <bwcode4u gmail com>
- To: vala-list gnome org
- Subject: Re: [Vala] help with java to vala
- Date: Fri, 26 Oct 2012 08:02:03 -0700
On 10/25/2012 09:24 PM, Calvin Walton wrote:
On Thu, 2012-10-25 at 13:00 -0700, bsquared wrote:
I attempted a simple test using this:
8< ------------------------------------------------
private static const Set<string> STATIC_SET;
static construct {
STATIC_SET = new HashSet<string> ();
STATIC_SET.add ("Hello");
STATIC_SET.add ("World");
}
------------------------------------------------ >8
with this result:
8< ------------------------------------------------
valac --pkg gee-1.0 hello_set.vala
hello_set.vala:5.4-5.47: error: `Gee.Set<string>' not supported as type
for constants
private static const Set<string> STATIC_SET;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hello_set.vala:8.3-8.16: error: The name `add' does not exist in the
context of `HelloTest.STATIC_SET'
STATIC_SET.add("Hello");
^^^^^^^^^^^^^^
hello_set.vala:9.3-9.16: error: The name `add' does not exist in the
context of `HelloTest.STATIC_SET'
STATIC_SET.add("World");
^^^^^^^^^^^^^^
Compilation failed: 3 error(s), 0 warning(s)
------------------------------------------------ >8
To my untrained eye this appears to indicate that I cannot use these as
constants. If I drop 'const' from the declaration it compiles and runs
correctly.
This is the expected result - if the Set is constant, then you can't
call the add method on it. It looks like the Gee Set type simply doesn't
support being used as a constant.
I think that the only types that you can actually use as constants in
Vala are ones that compile to basic/simple C types, and therefore could
be created using constant C initializers. If you have to write data to
the object at run-time to fill it, it's not a compile-time constant,
after all.
This limits you to using things like arrays of structures, for example.
If you really want a run-time initialized Set, then it will have to be
non-const.
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
Thanks for the response. I'll have to dig deeper into the java source
to determine why it was coded as a HashSet instead of an Array.
--
Regards,
Brian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]