简体   繁体   中英

Java code “NumberFormat nf = NumberFormat.getInstance();”

What is the difference between the followings

NumberFormat nf = NumberFormat.getInstance();

and

NumberFormat nf = new NumberFormat()

Why we need to declare NumberFormat object as the first one?

You can't use new NumberFormat() ; as the very first line of the Javadoc notes,

NumberFormat is the abstract base class for all number formats.

You can't directly instantiate an abstract class, so a creational pattern is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM