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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:39:09+00:00 2026-06-11T23:39:09+00:00

Suppose this code: public class Test{ public static void main(String[] args) { Test.testInt(new int[]{2,3});

  • 0

Suppose this code:

public class Test{

    public static void main(String[] args) {
        Test.testInt(new int[]{2,3});
        Test.testInteger(new Integer[]{2,3});
    }

    public static void testInt(Object... elements){
      System.out.println(elements[0] instanceof int[]);
    }

    public static void testInteger(Object... elements){
      System.out.println(elements[0] instanceof Integer);
    }

}

In both cases, one expected to have a one-dimensional array which contains 2 and 3.
So the expected output should be at first sight:

false
true

Surprise! the real output is:

true
true

UPDATE TO THIS POST:

Actually, it is not a good question since I haven’t realized that this case is in accordance with the Var-args rules.

To sum up, an int[] array cannot be autoboxed to Integer[] even when a Var-args is the argument; there’s no exceptional treatment.

  • 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-11T23:39:10+00:00Added an answer on June 11, 2026 at 11:39 pm

    You can’t autobox a primitive array to an “wrapper” array: an array is a totally different type! There are some quite clear use cases for autoboxing primitives. Those use cases don’t exist for arrays.

    Your method signature asks for at least one Object, and you supplied one: int[]. Your method signature also allows you to provide an array, which you do with Integer[].

    It’s also worth pointing out that all varargs methods can be invoked with arrays of the parameter type, which is what you’re doing with Integer. Since int isn’t an Object, your compiler treats the array as an Object.

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

Sidebar

Related Questions

In this code. public class Test { public static void testFun(String str) { if
class Program { static object test = new object(); static void Main(string[] args) {
Suppose I have the following classes: public class Test { public static void main(String[]
Suppose the classes has code like this: class C { public static void show()
Suppose I have a Java class like this: public class Test { static {
Suppose I have code segment namespace Test { public delegate void StaticticsDelegate(object sender,EventArgs e);
suppose you have the code template <template<class> class BaseType> class EST16 : public BaseType<int>
I have this code that suppose to place the marker by the latlng public
Suppose this C# code: using (MemoryStream stream = new MemoryStream()) { StreamWriter normalWriter =
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];

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.