The idea of implicit vs default

Pedro Lamarão pedro.lamarao at prodist.com.br
Mon Jan 22 13:38:37 UTC 2024


Em sáb., 20 de jan. de 2024 às 19:02, John Rose <john.r.rose at oracle.com>
escreveu:


> For another system which did it the other way, please look at how C++
> object constructors interact with C++ array creation.  It is awkward, hard
> to understand, bug-prone, and expensive.  We don’t choose to adopt those
> costs into the Java language or VM.
>

IIRC, one of the reasons C++ introduced "default constructors" was to
restore the optimized initialization of default initialized arrays for that
object. In C++, the presence of any explicitly defined constructor disables
the implicitly defined zero-argument constructor. But if one reintroduces
the zero-argument constructor explicitly, it is not guaranteed to have the
effect of "default initialization", as the body of that constructor is free
to do anything. Marking it as = default invokes the "default initialized
fields" definition, restoring the optimization. To my intuition, this is
generally the same as  the "implicit constructor" being proposed by
Valhalla. Some have argued that this is difficult to understand, but AFAIK,
this is not a particularly heavy pedagogical burden on C++.

-- 
Pedro Lamarão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20240122/ce692fe9/attachment.htm>


More information about the valhalla-dev mailing list