You aren't specifying the error correctly.
Look at the overloads for PrintStream.println()
. You'll notice that the only reference types are char[]
, String
and Object
.
Netbeans gives me the error
Exception in thread "main" java.lang.RuntimeException
: Uncompilable source code - reference to println
is ambiguous
both method println(char[])
in java.io.PrintStream
and method println(java.lang.String)
in java.io.PrintStream
match
Which is just the way we expected it to be: it can't choose between either of them since both are equally valid.
The reason why it does not mention the Object
overload can be found in the smallprint in the JLS at chapter $15.12.2. Compile-Time Step 2: Determine Method Signature:
For example, declaring m(Object...)
in a class which already declares m(Object)
causes m(Object)
to no longer be chosen for some invocation expressions (such as m(null)
), as m(Object[])
is more specific.
You can find this in the explanation of the first phase.