Re: Discrepancy in current hour
Eric Sosman wrote:
5) Refrain from calling non-final instance methods on objects
that haven't finished construction! This is a Big No-No;
Rhino wrote:
With regards to your fifth point, I'm afraid I still get a little
muddled when someone makes a generalized commment like that without
also pointing to the specific thing I've done wrong. Can you clarify
which object hasn't finished construction?
'TestHour'.
You call a bunch of methods from inside the constructor, ergo the object
hasn't finished construction when you call methods like
'getCurrentHour12HourClock()'. It is better (usually) to let an object finish
construction before it does anything useful.
(TAB characters removed for readability.)
public TestHour() {
System.out.println("The current hour on the 12 hour clock is: " +
getCurrentHour12HourClock() + ".\n");
System.out.println("The current hour on the 24 hour clock is: " +
getCurrentHour24HourClock() + ".\n");
System.out.println("The current time is: " + getCurrentTime() + ".
\n");
}
And please, please, please, please, please use narrower indentation for Usenet
code posts - a maximum of four spaces per indent level. It makes the code so
hard to read when you use such wide indentation. Stop using TAB characters
for indentation.
The output wraps horribly so I'll just summarize it verbally:
The hour still shows as 7 PM even though it was not yet 7 PM
when I executed the code.
The actual output still has a marginal chance of being useful to those of us
not there who attempt to help from here. Every time you redact information
you risk losing the piece that solves the puzzle.
--
Lew