Hey Gilad,
thanks for the explanation i must say that the specs are quiet
difficult
for me to understand but you are basicly stating that:
1. If you want to let the parent class let it run its constructor this
should
be done before the child constructor: Foo(a): super(a) { .... }
2. Because of the phases of object construction and the constrins it
gives us i cannot call the parent constructor halfway during the child
constructor (because the constructor ain a instance member)
Which means that if i want to call constructor logic of the parent
from
the child i should put this parent logic into another instance member
of the parent
class.
So in general (maybe obvious): the constructor of a object should
limit itself
as much as possible to the initialization (assigning) of its
properties and any
(excess) logic surrounding this should best be moved to another method
(in te parent class) so it can be
called as an instance member from the child constructor?
On Oct 12, 1:34 am, Gilad Bracha <
gbra...@google.com> wrote:
> Hi,
>
> All accessible instance instance members of all kinds can be accessed via
> super in the traditional ways.
>
> Constructors are different. They are not instance members. You don't call a
> super constructor the same way.
>
> This is because the construction process is carefully constrained, so that
> one can never see final instance variables in an uninitialized state (and if
> one wants, one can also initialize all other instance variables without
> exposing their uninitialized state).
>
> Object construction consists of several phases. Simplifying slightly, field
> initialization happens first, via an initializer list (written after the
> signature) and the constructor bodies are executed afterwards. You call the
> superconstructors initializer list during the first phase via the syntax
>
> Foo(a): x = 3, super(a) {}
>
> The body implicitly calls the super body before it starts.
>
> It is all in the spec. I agree we need a tutorial for this soon.
>