Click here to Skip to main content
12,302,647 members (64,823 online)
Rate this:
 
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 20: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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 27 Sep 2011
Copyright © CodeProject, 1999-2016
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