Re: [Vala] Using 'as' for casting?



On 08/07/2009 05:19 PM, Daniel Svensson wrote:
When converting my application to use Gtk.Builder I ended up with a
lot of code like this:

var lbl = builder.get_object("foo") as Gtk.Label;

And this caused me to try the following:

var time = Time.gm (unxtime as time_t);

as it was more readable than:

var time = Time.gm ((time_t) unxtime);

This however is not valid syntax, but maybe it should be? On IRC I got
the answer that if an 'as' would fail it would return null, and that's
why it shouldn't work.

I thought it was best to drop a mail to the list and see what people think.


That's right, but it's not just the fact it can return null. You can't use 'as' for simple types because there is no way to do run-time type check for them, so no way to find out whether cast is valid (until the segfault, of course). So there is no way 'as' could work for them.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]