java - incomparable types boolean and nulltype -


when compile code way, mentioned error:

public class symtree{ public static boolean issym(bt bt)     {         return(ismirror(bt.left, bt.right));     } private static boolean ismirror(bt lr,bt rr)    {        if(lr==rr==null)   (((error here)))         return true; ..... 

however when compile this

    private static boolean ismirror(bt lr,bt rr)    {        if(lr==rr)&&(lr==null))         return true; ....... 

i no error. error uncomparable types nulltype , boolean, non of compared objects boolean- both objects bt(binary tree) class, has been defined elsewhere. thank you!

the reason it's giving error because when write this:

if (lr==rr==null) 

the compiler interprets similar 1 of following:

if ((lr==rr) == null)  if (lr == (rr==null)) 

basically, you're comparing boolean condition (either lr==rr or rr==null) nullable type, doesn't make sense since booleans value types , can never null.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -