Re: [Vala] How to check if GLib.List is empty?
- From: Dmitry Golovin <dima golovin in>
- To: Luca Bruno <lethalman88 gmail com>, "vala-list gnome org" <vala-list gnome org>
- Subject: Re: [Vala] How to check if GLib.List is empty?
- Date: Tue, 02 Dec 2014 17:51:35 +0200
Hello all!
I just tried to compile this:
int main(string[] argv)
{
List<string> list = new List<string>();
assert( list == null );
return 0;
}
It compiles and runs. But this one doesn't compile:
int main(string[] argv)
{
List<string> list;
assert( list == null );
return 0;
}
So, variable should be initialized, even thought it is null after the initialization.
And vala doesn't have so called diamond operator (am I right?), so this code is not valid:
List<string> list = new List<>();
Would diamond operator be implemented in the future? Anyone needs it?
Regards,
Dmitry
02.12.2014, 17:38, "Luca Bruno" <lethalman88 gmail com>:
On 02/12/2014 16:34, Виталий Кирсанов wrote:
Hm, indeed. The following piece of code works fine:
int main(string[] argv)
{
List<string> list = new List<string>();
assert( list == null );
return 0;
}
So this seems to be the answer to my question. But still there are two
weird things in my opinion:
- Why I need to call operator new if the result value is still null?
Can't I simply declare a reference List<string> list; and then call e.g.
append()?
Yes, you can. "new List()" is just "null".
- I thought that only references appended with question mark sign (e.g.
List<string>?) can be null, cant' they?
There are several exceptions due to historical reasons. Null is quite
weak in Vala by default in several places.
There's an experimental non-null flag for valac, but that's not much
worked on.
Best regards,
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]