Skip to content

Instantly share code, notes, and snippets.

@billmote
Last active May 2, 2016 20:10
Show Gist options
  • Save billmote/66b389330b919ac2465580b9236f4e74 to your computer and use it in GitHub Desktop.
Save billmote/66b389330b919ac2465580b9236f4e74 to your computer and use it in GitHub Desktop.
Which do you prefer?
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