[Grace-core] Inheritance and object initialisation

Andrew Black black at cs.pdx.edu
Wed Jul 18 16:34:28 PDT 2012


On Jul 18, 2012, at 3:58 PM, Kim Bruce wrote:

> So, we could just decide Java is wrong and go on with our own analysis.  That may be the correct thing to do, but I'd like to understand better why Java did this.

Java isn't wrong, it's just different.   In java there is an implicit initialization method that is run before the "constructor". It's made up by concatenating the in-line code of the class whose instance is being created, and all its superclasses.

so the initialization of InnerSub.x to tmp is executed when tester.new InnerSub() is executed, as well as when tester.new InnerSup() is executed.


> 
> I'll just leave it for now as a puzzle that we should think about.  Please do let me know if you think my code somehow does not mirror the original grace code (or if you know another language that gives a different answer!).


Of course it doesn't mirror the Grace code: it uses Java class inheritance, not Grace object inheritance!  One of the reasons that we defined Grace to inherit from (already initialized) objects was to clear up this initialization mess!

	Andrew

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailhost.cecs.pdx.edu/mailman/private/grace-core/attachments/20120718/5474d1d5/attachment.html>


More information about the Grace-core mailing list