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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:17:46+00:00 2026-06-11T11:17:46+00:00

Why is it that, if you have, let’s say, these functions: void func1(Object o){

  • 0

Why is it that, if you have, let’s say, these functions:

void func1(Object o){
      //some code
}
void func1(Object[] o){
      //some code
}

You can call, for example:

func1("ABC");

but not :

func1({"ABC", "DEF"}); // instead having to write:
func1(new Object[]{"ABC", "DEF"});

Question: Is there any special reason why the constructor needs to be called on arrays ?

  • 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-11T11:17:47+00:00Added an answer on June 11, 2026 at 11:17 am

    The “array initialiser” is only available for declarations / assignments:

    Object[] o = { 1, 2 };
    

    Or for “array creation expressions”:

    new Object[] { 1, 2 };
    

    Not for method calls:

    // Doesn't work:
    func1({1, 2});
    

    It’s the way it is… You can read about it in the JLS, chapter 10.6. Array Initializers. An extract:

    An array initializer may be specified in a declaration (§8.3, §9.3, §14.4), or as part of an array creation expression (§15.10), to create an array and provide some initial values.

    Apart from it not being defined in the JLS right now, there seems to be no reason why a future Java version wouldn’t allow array initialisers / array literals to be used in other contexts. The array type could be inferred from the context in which an array literal is used, or from the contained variable initialisers

    Of course, you could declare func1 to have a varargs argument. But then you should be careful about overloading it, as this can cause some confusion at the call-site

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

Sidebar

Related Questions

The issue Let's say that I have example.com, example.org and example.net. All of these
let's say that I have some <TR style = background-color : red ;> and
Let's say you have several models that contain fields for address, postal code, province/country,
Let's say I have a JavaScript object that is made up of several key/value
Let's say that you have to implement some functionality that is not trivial (it
Let's say I have a bunch of related functions that have no persistent state,
Let's say that I have a SQLite database that I create in a separate
Let's say that I have an error in a php/mysql query : $query =
Let's say that I have something like this in my web.xml file. <filter name=foo>
Let's say that I have 3 fieldsets, each with 2 inputs: NAME and AGE.

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.