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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:26:11+00:00 2026-05-10T16:26:11+00:00

Consider the following method signatures: public fooMethod (Foo[] foos) { /*…*/ } and public

  • 0

Consider the following method signatures:

public fooMethod (Foo[] foos) { /*...*/ } 

and

public fooMethod (Foo... foos) { /*...*/ } 

Explanation: The former takes an array of Foo-objects as an argument – fooMethod(new Foo[]{..}) – while the latter takes an arbitrary amount of arguments of type Foo, and presents them as an array of Foo:s within the method – fooMethod(fooObject1, fooObject2, etc...).

Java throws a fit if both are defined, claiming that they are duplicate methods. I did some detective work, and found out that the first declaration really requires an explicit array of Foo objects, and that’s the only way to call that method. The second way actually accepts both an arbitrary amount of Foo arguments AND also accepts an array of Foo objects.

So, the question is, since the latter method seems more flexible, are there any reasons to use the first example, or have I missed anything vital?

  • 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-10T16:26:12+00:00Added an answer on May 10, 2026 at 4:26 pm

    These methods are actually the same.

    This feature is called varargs and it is a compiler feature. Behind the scenes is is translates to the former version.

    There is a pitfall if you define a method that accepts Object… and you sent one parameter of type Object[]!

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

Sidebar

Related Questions

Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): print
Consider following LINQ-to-NHibernate queries: var q1 = from se in query.ToList<SomeEntity>() where prop1 ==
Consider the following functions: function debug() { $args = func_get_args(); // process $args }
Consider the following sample: var Container = function(param) { this.member = param; var privateVar
Consider the following code in Python: class A(object): CLASS_ATTRIBUTE = 42 def f(self): return
Consider the following C# code: Decimal number = new decimal(8.0549); Decimal rounded = Math.Round(number,
I've been trying to create a criteria builder containing a belongsTo relation and have
Note: I'm posing this question to answer it myself, but other answers are welcome.
I am developing a application which requires to invoke a class function which is
My Java application needs to send an email out to all users once per

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.