Equality Testing with Hardcoded Strings

If you are going to use a String equality comparison that involves a hardcoded string, you might as well save yourself from some NullPointerExceptions and the extra null pointer check, put the hardcoded string as the method call-e instead of the parameter.

Instead of:

if ( foo.equals( "some static string" ) ){...}


if ( foo != null && foo.equals( "some static string" ) ){...}


if ( "some static string".equals( foo ) ){...}

2 thoughts on “Equality Testing with Hardcoded Strings

  1. Hello friends
    I say you’re sorry if I create off-topic
    But I recently had to locate a detailed article about ways to write essays for your university.
    I just discovered a fantastic report. Perhaps somebody else will want this material.

    In addition, whereas I was hunting for this article, I discovered that lots of individuals purchase dwelling works, compositions, papers and essays. I do not know how protected it can be and what high quality might be obtained within the finish. Who faced this problem, create, you create or decide to purchase? Had been you caught by the lecturer for this?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>