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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:18:24+00:00 2026-06-09T00:18:24+00:00

I just found out about a very interesting Java trick: void method1(Integer… a){ }

  • 0

I just found out about a very interesting Java trick:

void method1(Integer... a){
}

So you can give this method as many integers as you want.

Now if I have a similar (overloaded) method like this:

void method1(int a, int b){

}

Which method runs when I execute the following line:

method1(1, 2);

Well, I could find that out very easily by just testing it out with different method instructions but when I think about the “rules” in “overloading” methods then I have to make sure that every overloaded method must be identical so that the compiler knows exactly which one to use.

In my opinion, the code above shouldn’t work because the compiler should be confused. But when I try it out it works.

So.. does anyone know a bit more background information about this?

  • 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-09T00:18:25+00:00Added an answer on June 9, 2026 at 12:18 am

    To determine which method should be called, the compiler goes through the following list, as detailed in the JLS #5.3 and JLS #15.12.2:

    • an identity conversion (§5.1.1) => method1(int a, int b)
    • a widening primitive conversion (§5.1.2)
    • a widening reference conversion (§5.1.5)
    • a boxing conversion (§5.1.7) optionally followed by widening reference conversion ==> method1(Integer... a)
    • an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion.

    In your case, the first point applies and method1(int, int) is called.

    (To be more precise, your method uses varags and has a lower priority than a simple boxing conversion. In other words, if there were a method1(Integer a, Integer b) it would come before method1(Integer... a) in the hierarchy)

    Why is it so? A comment in 15.12.2 give a hint:

    This guarantees that any calls that were valid in the Java programming language before Java SE 5.0 are not considered ambiguous as the result of the introduction of variable arity methods, implicit boxing and/or unboxing.

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

Sidebar

Related Questions

I just found out about ie7-js ; IE7 is a JavaScript library to make
I just found out about superfish and currently using it on an asp.net. The
I just found out about Alice and Scratch. I will be implementing those pretty
I just found out about yield return , I seems really nice. I use
I've just found out about View States in Flex (v3.0), but I am not
Scheme relative URLs (network-path references) are something that I've just found out about -
I just found out this weird behavior, is this a bug or what am
I just can't figure this out - I've tried positioning, floating and z-index, but
Just found out that the video output of the iPad is not a system
I just found out how to loop an array based on another array, but

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.