4 ms·
It could be allowed. Consider the case of var-args method called with a null value. Say you call the method ambiguousNull(String ...args) like so: ambiguou
by justin_oaks 10y ago
It could be allowed. Consider the case of var-args method called with a null value. Say you call the method ambiguousNull(String ...args) like so:
ambiguousNull(null);
Should args be null? Or should args be new String[]{null}? In the absence of any more information the compiler chooses the first, but may still issue a warning. But you can clearly disambiguate by casting:
ambiguousNull((String)null); // args is null
ambiguousNull((String[])null); // args is a 1-element array
- guelo 10y agoSo given int something() { } String something() { } A hypothetical calling syntax could be (int)something(); Or the compiler could even choose one for you with a warning. Seems like a good suggestion for Java 10.
- lgas 10y agoIt seems like a in the case of var args, the args should always be an array, since the meat of most var args based functions is iterating over that array.