Re: [Vala] Converting nullable to non-nullable types



Sam Wilson píše v Čt 25. 02. 2010 v 21:43 -0500:
On Fri, 2010-02-26 at 00:43 +0100, Jiří Zárevúcky wrote: 

Here's a little trick you might like:

[code]

errordomain MyError {
    FAILED;
}

T throwerror<T> (string str) throws Error {
    throw new MyError.FAILED (str);
}

int func ()
{
    int? i = null;
    int j = i ?? throwerror<int> ("hello");
    return j;
}

[/code]


Looks great, but I can't get it to compile with experimental non null
since the ?? operator is returning an 'int?'


That's a bug. ?? should have the second operand's type.

IMHO, as nice as this solution is, it seems a bit hackish for a language
that claims to support non-null types.

Remember that non-null checking is experimental. That means it's not
supposed to be complete and bug-free at this point.

  Overall, Vala provides very few
features that make N.N. types more attractive compared to regular types
and personally I find them a pain to work with


Nobody's forcing you. It's an experimental feature you need to
explicitly turn on. You have chosen to do so, you must bear the
consequences - bugzilla awaits you :-P

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy



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