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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:21:18+00:00 2026-06-05T22:21:18+00:00

I use java 7, and I create a varargs method public class JavaApplicationTest {

  • 0

I use java 7, and I create a varargs method

public class JavaApplicationTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        addBundleMessage("b", Integer.SIZE, "key", (Object) null);
    }

    public static void addBundleMessage(String bundleName, Integer severity, String key, Object... params) {
        if (params == null)
            System.out.println("params Is null");
        else
            System.out.println("Params not null");
    }
}

If I don’t cast the object, the IDEs Netbeans or Eclipse complains but it compiles :

non-varargs call of varags method with inexact argument type for last
parameter

When No cast : it display params Is null

When I cast null to (Object) it display Params not null

When I cast null to (Object[]) it display params Is null

Is it normal behavior ?

  • 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-05T22:21:21+00:00Added an answer on June 5, 2026 at 10:21 pm

    Yes, that is “normal” behaviour.

    The confusion comes from varargs being bolted on to the language later and being implemented using an array as the “real parameter” to hold the variable number of parameters.

    public static void addBundleMessage(String bundleName, Integer severity,
       String key, Object... params) {
    

    is almost the same as

    public static void addBundleMessage(String bundleName, Integer severity,
       String key, Object[] params) {
    

    and under the hoods, the params are passed wrapped as an Object[].

    However, you still have the option to pass in that array yourself.

    If you use (Object[]) null, you get a parameter (that is null).

    If you use (Object) null, it uses the varargs method, so it passes in an array to hold the parameters (of which there is only one which is null).

    For “normal use” of a varargs method, params will never be null. The “worst” you can get is an empty array (if there are no arguments at all).

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

Sidebar

Related Questions

I am trying to use Java's useDelimiter method on it's Scanner class to do
I use Java Runtime.getRuntime().exec(command) to create a subprocess and print its pid as follows:
I'm trying to use a method from a Java class whose parameter type is
We can't use java.text.SimpleDateFormat, so is there any way to create date object from
I want to use pooled connections with Java (because it is costly to create
I use java implementation for Camel. Should I use different class for each route
i use java reflections to get methods used in a class.I also want to
I'm using java generics and varargs. If I use the following code, I'll get
I'm currently starting to learn to use java to create dynamic websites. I've started
I'm trying to use Java ( not XML ) to create a LinearLayout with

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.