Last active
May 2, 2016 20:10
-
-
Save billmote/66b389330b919ac2465580b9236f4e74 to your computer and use it in GitHub Desktop.
Which do you prefer?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeClass { | |
someMethod(String className) { | |
// I see this more often | |
if (!TextUtils.isEmpty(className)) { // We have to ensure that className isn't null before calling equals() | |
if (className.equals(SomeClass.class.getName()) { | |
// do something | |
} | |
} | |
} | |
// I prefer this | |
someOtherMethod(String className) { | |
if (SomeClass.class.getName().equals(className)) { // But if we flip the expression then we can bypass the extra if-statement | |
// do something | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment