I'm new to Java and I have a beginner question:
NumberFormat
is an abstract class and so I assume I can't make an instance of it. But there is a public static (factory?) method getInstance()
that allow me to do
NumberFormat nf = NumberFormat.getInstance();
I'm quite confuse. I'll be glad if someone could give me hints on:
Thank you.
DecimalFormat
, for example). Having a constructor for an essentially unknown number format is pretty useless.getInstance()
method is a so-called factory method. It returns a matching number format for the current locale. Since it is not known what kind of sub-class is required at compile-time, it returns a NumberFormat
, however, the instance itself, will be of a sub-type, obviously (since you can't create instances of abstract classes).NumberFormatFactory
somewhere which would have the factory methods.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With