As 4Castle suggest, the reason is that
System.out.println(...);
is not just 1 method but instead many many different methods taking different parameters

This is known in java as method overloading
Behind the source code:
println is calling print
print is calling write
If write(..)
is using a char[]
then a NPE is happening because the code is trying (among others) to get the length of the array which is null referenced
private void write(char buf[]) {
try {
synchronized (this) {
ensureOpen();
textOut.write(buf);
textOut.flushBuffer();
charOut.flushBuffer();
if (autoFlush) {
for (int i = 0; i < buf.length; i++)
if (buf[i] == '\n')
out.flush();
}
}
}
On the other hand, printing a int[]
will be ending up into a calling println(Object x)
where String.valueOf
is invoked
public void println(Object x) {
String s = String.valueOf(x);
synchronized (this) {
print(s);
newLine();
}
}
and as you can see
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
the valueOf(null)
returns null
:)