getting used to Java - question about "style"

From: glunk (stowe_at_whackthisvsac.org)
Date: 06/30/04


Date: Wed, 30 Jun 2004 08:54:10 -0400

I am working on my very first Java project. I have been familiar with OO
design for a long time. But I have never put the real thing into practice
(formerly a VB 6 programmer which only buys you encapsulation). My company
is shifting away from VB / ASP solutions and bringing in Java and JSP. I am
one of the ground breakers (God help me).

I am reading a book that a collegue gave me called "The Elements of Java
Style" by Vermeulen, Ambler, Bumgardner, Metz, Misfeldt, Shur and Thompsaon.
(A lot of authors for a really skinny book.) Anyway, ONE OF THE RULES THAT
THEY HAVE IS

"Do not call nonfinal methods from within a constructor."

They go on to explain

"Subclasses may override nonfinal methods and Java will dispatch a call to
such a mrethod according to the actual type of the constructed object -
before executing the derived class constructors. This means when the
constructor invokes the derived method, the derived class may be in an
invalid state. To prevent this, call only final methods from the
constructor."

I cannot understand what this says or means. I know that a final method is
one that cannot be overridden. I do not understand what this parapgraph is
intending to warn me against doing or why. Can someone explain, preferably
with an example?

Thanks!

S



Relevant Pages

  • Re: getting used to Java - question about "style"
    ... > I am reading a book that a collegue gave me called "The Elements of Java ... > before executing the derived class constructors. ... > constructor." ... void print() { ...
    (comp.lang.java.programmer)
  • Re: 2 newbie questions
    ... > the volume of a fish tank and a third that ties everything together. ... You create a .java file. ... Then you modify this by asking it to create a constructor method and calling ... When you have a series of variables in some array, and you have an array for ...
    (comp.lang.java.help)
  • Re: New (as in days) to Java - question about "super()" method
    ... > Hi, I'm Don, and I'm a serious greenie when it comes to Java. ... learn Java because Object Oriented Programming is quite different from ... > guts out of the method involved (a constructor, I believe, is the ... inheritance: if I have a class and I want to add some extra ...
    (comp.lang.java.programmer)
  • Re: Implicit overloads, non static
    ... you've disputed whether it's a matter of implementation rather ... that's clearer - but I wasn't disputing that. ... > I find a lot of things hard in Java. ... I'm not sure I'd call that a copy constructor myself, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Road to Clojure Survey
    ... constructor taking another Collection as a parameter, ... on Java collections require mutation) is not wrong in principle. ... Common Lisp either, for that matter, even if in general Common Lisp ... JDK 1.1 - that was before the Collection interfaces were defined. ...
    (comp.lang.lisp)