When using the getInstance() method of the abstract java.text.NumberFormat class, what is the actual class of the return value? -


This question spreads to one. I think this question is enough for the qualifications to ask yourself.

In response to that question, it was said that

  NumberFormat en = numberformat.justestation (locale.US);  

Returns an object that is a subcategory of the java.text.NumberFormat class. It makes sense to me why the return type can not be an example of just NumberFormat because it is an abstract class. Rather, it was said that the returned object is an example of at least NumberFormat , but in fact something else.

My question is this: is the class of the object in particular which has returned? In the Sun Documents I see that only subclass are ChoicesFormat and DecimalFormat . Is there some type of screen compiler behind magic?

Thank you in advance!

specific type is not specified because it is a sub class of NumberFormat It may also depend on the location you use. To implement certain locations correctly, the ChoiceFormat may be required, for others the decimalfile is sufficient and for the third locale, they also return local-specific implementation You can.

The fact is that it is not specifically defined as compared to the intangible base class, the method allows for this kind of change in the implementation without changing the signature to accommodate such changes. .

You can easily verify which type is

< / P>


Comments