Original Post
Hi all,
I have a question about casting null. Currently, casting null raises a script exception:
I 'd expect a more C-like approach, like casting null to something just returns null (instead of raising an exception). Is that behaviour intended? Or maybe there's an option somewhere to turn that off?
Just as I was writing this post, I did the following test:
Guess what? The output is "B is null" and there's no exception raised. Exactly what I 'd expect, although if an exception was raised in this case I would also understand it (since "B" has no relation whatsoever to "I").
Thanks,
Yiannis.
I have a question about casting null. Currently, casting null raises a script exception:
Something@ s = cast<Something>(null); // <- raises exceptionI 'd expect a more C-like approach, like casting null to something just returns null (instead of raising an exception). Is that behaviour intended? Or maybe there's an option somewhere to turn that off?
Just as I was writing this post, I did the following test:
interface I { void test(); }
class A : I { void test(){} }
class B { } // notice that B does NOT implement interface I...
void main()
{
I@ i = A();
B@ b = cast(i);
if (b is null) print("B is null");
else print("B is NOT null");
}
Guess what? The output is "B is null" and there's no exception raised. Exactly what I 'd expect, although if an exception was raised in this case I would also understand it (since "B" has no relation whatsoever to "I").
Thanks,
Yiannis.