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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:47:14+00:00 2026-05-10T13:47:14+00:00

I saw this in an answer to another question , in reference to shortcomings

  • 0

I saw this in an answer to another question, in reference to shortcomings of the Java spec:

There are more shortcomings and this is a subtle topic. Check this out:

public class methodOverloading{      public static void hello(Integer x){           System.out.println("Integer");      }       public static void hello(long x){           System.out.println("long");      }       public static void main(String[] args){          int i = 5;          hello(i);      } } 

Here "long" would be printed (haven’t checked it myself), because the compiler chooses widening over auto-boxing. Be careful when using auto-boxing or don’t use it at all!

Are we sure that this is actually an example of widening instead of autoboxing, or is it something else entirely?

On my initial scanning, I would agree with the statement that the output would be "long" on the basis of i being declared as a primitive and not an object. However, if you changed

hello(long x) 

to

hello(Long x) 

the output would print "Integer"

What’s really going on here? I know nothing about the compilers/bytecode interpreters for java…

  • 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. 2026-05-10T13:47:15+00:00Added an answer on May 10, 2026 at 1:47 pm

    In the first case, you have a widening conversion happening. This can be see when runinng the ‘javap’ utility program (included w/ the JDK), on the compiled class:

    public static void main(java.lang.String[]);   Code:    0:   iconst_ 5    1:   istore_ 1    2:   iload_ 1    3:   i2l    4:   invokestatic    #6; //Method hello:(J)V    7:   return  } 

    Clearly, you see the I2L, which is the mnemonic for the widening Integer-To-Long bytecode instruction. See reference here.

    And in the other case, replacing the ‘long x’ with the object ‘Long x’ signature, you’ll have this code in the main method:

    public static void main(java.lang.String[]);   Code:    0:   iconst_ 5    1:   istore_ 1    2:   iload_ 1    3:   invokestatic    #6; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;    6:   invokestatic    #7; //Method hello:(Ljava/lang/Integer;)V    9:   return  } 

    So you see the compiler has created the instruction Integer.valueOf(int), to box the primitive inside the wrapper.

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

Sidebar

Related Questions

I saw this question asked about C# I would like an answer for PHP.
I saw this question on SO about casting, and the answer specifically mentioned numeric
I am 90% sure I saw this answer on stackoverflow before, in fact I
I saw this same question for VIM and it has been something that I
I saw this quote on the question: What is a good functional language on
I saw this quote in this question : MS support is poor, except when
I saw this question and it motivated me to look again (without success) at
I saw this question that asks given a string smith;rodgers;McCalne how can you produce
I saw this post on SO: UISearchBar solid color But no answer was provided.
In an answer on Stack Overflow, I saw this code: CREATE TABLE Favorites (

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.