Re: [Vala] casting out parameters



And if it's a subclass? Which is what 'as' does.

----- Original message -----
On Wed, 2010-05-26 at 15:41 +0200, pancake wrote:
Would love to see this dynamic casting supported by the language..
Should I open a bug?

As Nor Jaidi Tuah wrote, the declaration of the method `test` does not
guarantee that `foo` is set to an instance of `Bar`. The method could
also be implemented as follows:

void test(out Foo foo) {
        foo = new Foo ();
}

If the compiler accepted your `main` method, you'd have a variable of
type Bar pointing to an object of type Foo, and this should never
happen. The compile error you get is intentional and not a bug.

Jürg




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