Let's split the question between the vararg and the null.
vararg
The point of varargs is to send an array of data without having them in the caller's code as an array, but as individual variables or constants.
Calling the varargs may not be very intuitive, here's what happens in various cases :
method("", "1", "2"); // vargs is {"1", "2"}
method(""); // vargs is {}, the empty array (it is not null)
method("", null); // vargs is {null}, size 1 array containing the element 'null'
method("", (Object[])null); // vargs is null, a null instance
Note that the third case is considered bad form. For example, you receive a warning if the null is a constant (not stored in a variable).
Note that in the fourth case, you are really looking for problems ! ;-)
Class of Null
Now, we are talking of an array that contains a null value, not about a null array (that was sorted out in the previous part).
General case
Null can be of any class (all at a time). But instanceof
will always return false.
Put into a map
If one value is null, you need to think about what you want to do. Obviously, getClass() cannot be called on a null value. So you can choose between:
- skip the null value, not add it in the map
- choose a class you want to associate to null. This could be Object, or Void, or another specific classe. Think about what you want to do with it, because the association is arbitrary...