On Mon, Nov 10, 2014 at 3:30 PM, Виталий Кирсанов <krokozia...@gmail.com> wrote: > > Hello list. > > Is 'this' always null in constructors? The following code produces a > run-time error: > > public class Foo > { > Foo() > { > assert( this != null ); > } > }
What error are you getting? "this" is /not/ null inside constructors... That would be weird :) As is, this code does not compile because there's no "static main method" (which is OK). If I add a trivial main function (outsize the class) in which I instantiate Foo, I get that the constructor is not public; so access is restricted (which is also OK). None of this errors is saying that "this" is null. For example, this works: public class Foo { Foo() { assert(this != null); } * static int main() { var f = new Foo(); return 0; }* } (Also a version with the main method outside the class but the constructor made public should work). > > Is there a way to get the true value of this in the constructor? I guess, > probably not. As far as I understand references in vala are somewhat > similar to shared_ptr<> pointers in C++ and vala classes to > enable_shared_from_this<> C++ subclasses. If the reasons are also similar, > it would be sad. > > But probably vala gives a solution to this? > > > BR, Vitaly Kirsanov > skype: vkirsan > _______________________________________________ > vala-list mailing list > vala-list@gnome.org > https://mail.gnome.org/mailman/listinfo/vala-list _______________________________________________ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list