Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1194 :

Posted: Sun Sep 23, 2012 2:38 am
by ETS User
In solution description , you mentoned
C:\works\nbtestproject\src\TestClass.java:46: reference to println is ambiguous, both method println(char[]) in java.io.PrintStream and method println(java.lang.String) in java.io.PrintStream match System.out.println(null + true); //1

Shouldn't there be System.out.println(null); to back up this statement, because System.out.println(null/true + true/null);always give compilation msg : "Operator + cannot be applied to null/boolean or boolean/null"

Re: About Question enthuware.ocajp.i.v7.2.1194 :

Posted: Sun Sep 23, 2012 7:13 am
by admin
No, compiler thinks that System.out.println(null + true); matches System.out.println(String); as well as System.out.println(char[]); because it is not able to figure out the type of null+true. So both the methods are kind of equidistant from this call.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1194 :

Posted: Fri Jun 22, 2018 5:53 pm
by flex567
>String getString() { return null; }
How would this even compile if null is not a String?

Re: About Question enthuware.ocajp.i.v7.2.1194 :

Posted: Fri Jun 22, 2018 10:05 pm
by admin
Java allows returning null from any method whose return type is a reference type.