Re: Call virtual function in constructor
* Pavel:
Alf P. Steinbach wrote:
In passing, check out[1] <url:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6596304>. :-)
Yes, people make mistakes. JVM Specs is pretty clear about what is
supposed to happen and that is exactly what happens. The relevant piece
of the standard is easy to read and follow:
http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#19124
Hopefully when the "bug" comes to the developer, they will close it
instead of "fixing" it.
I think it clearly illustrates the dangers of those virtual calls from
constructors.
For the problem is that code is maintained, not just originally written
(about 80% of coding work is maintainance, as I recall the statistics).
When a maintainance programmer (which might be oneself) comes along and
e.g. adds an initializer to a class member, or falls for the temptation
to let the downcalled function do something with or to the derived
class' members, or adds a call there to a function that someone else
will in turn make do something with or to the derived class' members,
perhaps even in a class derived from the derived one, where the context
of the call is not at all clear, then presto, a new bug or set of bugs.
Cheers,
- Alf