Re: DateFormat question



On Thu, 31 May 2007 19:51:12 +0100, <hrosser@xxxxxxxxx> wrote:

I have used code like:
DateFormat df = DateFormat.getDateInstance( );
which according to the API: "Gets the date formatter with the default
formatting style for the default locale". My question is: Since the
DateFormat class is abstract, what is going on behind the curtains? I
have to assume that some un-named but concrete subclass of the
DateFormat class is created, compiled, and instantiated, then assigned
to the df reference variable.
Is this the case?


It's something along those lines (although the class won't be dynamically compiled).

The class isn't necessarily unnamed. It may be an anonymous inner class, it could be a named static nested class, or maybe it is a package scope top-level class that isn't documented in the API. Or it could just be that you get an instance of SimpleDateFormat, which is a public class that you can instantiate directly. I don't know exactly which type is returned, but the idea is that you don't need to know. If you are curious, you can call getClass() on the object returned and print out its type.

If you want to know exactly what happens, the source code is included in the src.zip file that is installed with the JDK (assuming you check the source option when you install it).

Dan.

--
Daniel Dyer
http//www.uncommons.org
.



Relevant Pages

  • Re: DateFormat question
    ... formatting style for the default locale". ... DateFormat class is abstract, what is going on behind the curtains? ... top-level class that isn't documented in the API. ... I see its an instance of SimpleDateFormat ...
    (comp.lang.java.programmer)
  • DateFormat question
    ... which according to the API: "Gets the date formatter with the default ... formatting style for the default locale". ... DateFormat class is abstract, what is going on behind the curtains? ...
    (comp.lang.java.programmer)
  • Re: Date parsing bug?!
    ... >> Look at the API. ... it inherits that from DateFormat. ... DateFormat has method isLenient() which is true by default. ...
    (comp.lang.java.help)
  • Re: Date parsing bug?!
    ... Look at the API. ... it inherits that from DateFormat. ... Steve W. Jackson ...
    (comp.lang.java.help)
  • Re: Date parsing bug?!
    ... > Look at the API. ... > You'll note that SimpleDateFormat doesn't have a method parse. ... it inherits that from DateFormat. ...
    (comp.lang.java.help)