Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:29:43+00:00 2026-06-09T13:29:43+00:00

Consider the following code: NumberFormat format = NumberFormat.getInstance(); format.setMinimumFractionDigits(spotDecimalPlaces); format.setMaximumFractionDigits(spotDecimalPlaces); Is it safe? Is

  • 0

Consider the following code:

NumberFormat format = NumberFormat.getInstance();
format.setMinimumFractionDigits(spotDecimalPlaces);
format.setMaximumFractionDigits(spotDecimalPlaces);

Is it “safe”? Is NumberFormat.getInstance() guaranteed to return a new NumberFormat object each time?

Or is there a possibility that getInstance() returns the same instance? (in which case this code would affect everywhere else in the JVM that happens to use getInstance…)

Looking at the source code it seems like it returns a new instance each time. The JavaDoc is frustratingly vague on the matter.

If the above code really is “safe”, then it seems to me that getInstance() is a poor name for this method – that it should have been called createInstance().

Is NumberFormat.getInstance() guaranteed to always return a new instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:29:44+00:00Added an answer on June 9, 2026 at 1:29 pm

    Yes, it’s safe. The code either get an instance from a NumberFormatProvider (which must, according to the documentation, return a new instance), or it creates a new instance of DecimalFormat.

    Logically, since NumberFormat is mutable, returning the same instance or cached instances would make the method completely unusable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: char* p = new char[2]; long* pi = (long*) p;
Consider the following code sample that uses MEF to create an object of type
Consider the following code: function authenticate(){ $this->session->set_userdata('logged_in', true); } How do I return this
Consider following code: ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(2134); aList.add(3423); aList.add(4234); aList.add(343); String tmpString
Consider the following code, which simply calls a method on each member of a
Consider the following code Snippet Form form2 = new Form(); test(form2); form2.Show(); public void
Consider following code public class City { public string Name { get { return
Consider the following code: void Handler(object o, EventArgs e) { // I swear o
Consider the following code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Consider following code, I want to make it a thread safe class, so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.