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 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
0 Dnyaneshwar@Pune 1,300
1 Sergey Alexandrovich Kryukov 660
2 OriginalGriff 329
3 ravikhoda 300
4 Manas Bhardwaj 240
0 Sergey Alexandrovich Kryukov 11,194
1 OriginalGriff 6,867
2 Peter Leow 4,795
3 Abhinav S 3,838
4 Maciej Los 3,575


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