On 2012-07-13 11:24, Jonas Drewsen wrote:

I Agree. Looking at the Groovy link from Christophe I noticed their Safe
Navigation Operator ?.

Basicly it returns the final value in a dereference chain or null if any
objects in the chain are null:

// a is null if user or address or street is null. No exception thrown.
auto a = user?.address?.street;

But what would the static type of "a" be? I tried this:

class Foo {}

void main ()
{
    auto a = true ? new Foo : new Object;
    static assert (is(typeof(a) == Object));
}

And it passes. You loose static typing.

How would the type of "a" be resolved if there's a field/method that returns a value type in the chain? Compile time error?

--
/Jacob Carlborg


Reply via email to