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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:47:06+00:00 2026-06-14T14:47:06+00:00

I have a method that I want to expand (rather than writing a new

  • 0

I have a method that I want to expand (rather than writing a new method which does basically the same thing), by adding an unknown number of parameters to the end of the list of parameters.

If I do this, will I have to change all the calls to the method? I guess the question is, does the unknown parameter include the case there being no parameter passed in at all?

For instance, if I have a method:

queryFactory(int [] typeArgs, int queryType, int[] ... args){}

Could I call:

queryFactory(typeArgsInstce, queryTypeInstce)

And then when I need to add parameters to the query call:

queryFactory(typeArgsInstce, queryTypeInstce, argsInstce)

Where argsInstce is an array of integers containing extra arguments.

I would like to just edit this method rather than writing a new one which does almost the exact same thing except it has some arguments to add to queries. I will simply write another method if by editing this one I will have to change every other call to this method.

  • 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-14T14:47:07+00:00Added an answer on June 14, 2026 at 2:47 pm
    public static void main(String[] args) {
        method(1);      // <- compile error
        method(1,2);
        method(1,2,3);
        method(1,2,3,4);
    }
    
    private static void method(int i1, int i2, int...i3) {
        // do something
    }
    

    So to answer the question in words: we need 2 arguments at minimum. This passes an empty array ´i3[]´ to the method. Arguments number 3 and above are treated as array values.


    It makes no difference…

    public static void main(String[] args) {
        method(new int[]{1});      // <- compile error
        method(new int[]{1},2);
        method(new int[]{1},2,new int[]{3,4});
        method(new int[]{1},2,new int[]{3,4},new int[]{5,6});
    }
    
    private static void method(int[] i1, int i2, int[]...i3) {
        // do something
    }
    

    The varargs parameter has to be the last so it won’t conflict with the first array

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

Sidebar

Related Questions

I have a method CreateAccount(...) that I want to unit test. Basically it creates
Basically, if I have a method (or several methods) that I want to expose
I have a method that I want to test which expects an IEnumerable<T> as
I have a method: myMethod() {} that I want to make accessible to javascript.
Say I want to have a method that takes any kind of number, is
I have a method that returns a list of type string. I want to
I have a method running on the EDT and within that I want to
I have a method in a class in another file that I want to
Okay, so I want to have a generic method that can read data from
I have a method song_link that calls link_to internally. I want the caller to

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.