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 7016069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:44:11+00:00 2026-05-27T22:44:11+00:00

Based on the snippet below: // as primitive MyClass.primitiveMethod(double val); // method signature MyClass.primitiveMethod(12);

  • 0

Based on the snippet below:

    // as primitive
    MyClass.primitiveMethod(double val); // method signature
    MyClass.primitiveMethod(12);         // ok

    // as object
    MyClass.objectMethod(Double val); // method signature
    MyClass.objectMethod(12);         // error
    MyClass.objectMethod(12d);        // ok
    MyClass.objectMethod((double)12); //ok

Q1: While both 12d and (double)12 seem to work, are there any difference between specifying suffix and explicit casting? (behaviour/performance)

Q2: Why MyClass.objectMethod(12) must be considered an error? While 12 is supposed to be resolved to an Integer object, can’t Java be smart enough to know that 12 is also a value Double value and just accept it?

  • 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-27T22:44:12+00:00Added an answer on May 27, 2026 at 10:44 pm

    For the first question: I’d expect the conversion to double to be performed by the compiler, but I wouldn’t like to say for sure without checking. I’d use the suffix instead, for clarity. (If I need to check, that means anyone maintaining the code would have to check too… why not just use a literal of the right type to start with?)

    12 is resolved to an int, not an Integer – and there’s no implicit conversion from int to Double. Just because there’s an implicit conversion from int to double and another from double to Double doesn’t mean there’s one straight there.

    It could have been included, of course – but it would have meant making the language more complicated for a pretty small level of benefit.

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

Sidebar

Related Questions

Based on the below snippet from a silverlight control how do I make the
Edit 2: Below is a code snippet based on DuffyMo's response that illustrates how
Can someone explain the following code snippet for me? // Bind base object so
i'm trying to print a record in NVelocity based on certain condition: Below is
SOLUTION Refer to my answer below: issues with form/iframe based file upload in Opera
I'm using the getExcerpt() function below to dynamically set the length of a snippet
I have the following snippet: string base= tag1[j]; That gives the invalid conversion error.
In the below code snippet, template<typename T1> void func(T1& t) { cout << all
Below i have a bit of code which assigns values based on the values
Below is a snippet of PHP that I need to get working, I need

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.