Tom Kowalski wrote:I have discovered today really strange (for me) thing in Java. On one hand it makes sense, but on the other, I just want to scream 'What the heal?'. I put it here, because it might be useful for people who are learning for SCJP.
Good point ! When I tried compiling it, the compiler throws up this informative warning:
warning: non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
foo(new String[] {"j","a","v","a"});
So, in essence when you pass a String[] to foo, the call is treated as a non-varargs call.