Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
Please help me on converting the below inline if java code to if else.
 
public boolean equals(final Object obj) {
      boolean result = true;
     
     if (level != null ? !level.equals(log.level) : log.level != null)
     {
          result = false;
     }
      
      return result;
  }
Posted 26-Sep-11 21:54pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

/**
* returns in inverse logic
*/
public boolean equals(final Object obj) { 
    if (null != level ){
        if(null != log.level){  // null check first
            if(false == level.equals(log.level))  {
                return false;
            }
        }
        return false; // log.level is null
    }
    return true; // equals
}
      
 
wired to return in inverse logic - you should change that.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 27 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100