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

  • SEARCH
  • Home
  • 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 6989957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:16:56+00:00 2026-05-27T19:16:56+00:00

In OpenJDK, for the method: public static Double valueOf(double d) The javadoc says: Returns

  • 0

In OpenJDK, for the method:

public static Double valueOf(double d)

The javadoc says:

Returns a Double instance representing the specified double value. If a new Double instance is not required, this method should generally be used in preference to the constructor Double(double), as this method is likely to yield significantly better space and time performance by caching frequently requested values.

Here’s the actual code:

public static Double valueOf(double d) {
    return new Double(d);
}

The cache is a lie! What’s going on here?

  • 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-05-27T19:16:57+00:00Added an answer on May 27, 2026 at 7:16 pm

    The method exists for many types: Integer, Long, BigDecimal and others and the documentation is always the same: Under some circumstances (which aren’t defined), the method can return the same result.

    AFAIK, the caching is only implemented for integer types and it returns cached instances for values between -128 and 127 (most common values). For BigDecimal, the cache currently works for values from 0 to 10.

    Later versions of Java might extend this behavior to other values/more types. So it’s smart to use this code today because it might make your code faster tomorrow (and the code won’t be slower today).

    The Java compiler, for example, uses this API when generating code for autoboxing.

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

Sidebar

Related Questions

CentOs 5.4, OpenJDK Runtime Environment (build 1.6.0-b09) MathContext context = new MathContext(2, RoundingMode.FLOOR); BigDecimal
Consider this code from the official OpenJDK source of java.awt.font.TextLayout : public final class
The following class: public class StaticMethodsDemo { public static class A { public static
How can I install OpenJDK's Javadoc via command line in Ubuntu 11.10?
Is it possible to browse the source code of OpenJDK online, just like I
How do I call a method of a class dynamically + conditionally? (Class is
everyone. I used openjdk-7 on arch linux. I started to learn Java recently, and
I've taken a look into OpenJDK source code of CopyOnWriteArrayList and it seems that
I'm browsing through OpenJDK sources and cannot find the place where optimized code is
Can I install just OpenJDK without proprietary Sun JRE/JDK and use NetBeans and Eclipse

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.