Sam Wilson píše v Čt 25. 02. 2010 v 21:58 -0500:
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]Would this also be a valid way to check for null? T unbox<T>(T? v, string str) { if (v == null) throw new MyError.FAILED(str); return (T)v; }
I suppose it should work quite the same, but I'm not sure how does Vala cope with nullable -> non-nullable casts.
Attachment:
signature.asc
Description: Toto je digitálně podepsaná část zprávy