• nasch (unregistered) in reply to Severity One
    Anon:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    Can we get another 50 or 60 answers to this question? I'm not sure the horse is quite dead yet.

  • (cs) in reply to ideo
    ideo:
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.
    Jaime, is that you?

    Oh, OK. So I guess all Hispanics look alike?

  • Tnay (unregistered) in reply to Anon

    !"".equals(object) is the same as !(object.equals("")), except that it will not throw a null pointer if object is null;

  • nasch (unregistered) in reply to Tnay
    Tnay:
    !"".equals(object) is the same as !(object.equals("")), except that it will not throw a null pointer if object is null;

    Thanks! Just 49 to go!

  • _TB_TB_ (unregistered) in reply to Anon
    !"".equals()
    means "not empty string", and since inside
    "".equals()
    we have trim()-med string (white spaces trimmed), we check if the string is something more than spaces ;)
  • Frank Bakker (unregistered) in reply to Anon

    I would say that !"".equals(...) is a pretty 'cool' way to check for an enpty string :-)

  • dev < null (unregistered) in reply to Anon

    !"".equals() simply means "not equal to an empty string"

  • k42 (unregistered) in reply to Olius

    Dude, aspergers don't grow in the desert, and it isn't even the right season for them, anyway.

    (Captcha: abigo - you're usually doing something right if there's only one of them and not two to the n of 'em)

  • BubbleSort (unregistered) in reply to Anon

    !"".equals() is probably a check that the FieldName with white space removed is not equal to an empty string. The '!' is the NOT operator, the '""' is an empty string, and the 'Trim()' command removes white space.

  • anonymous (unregistered) in reply to Anon

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    Wouldn't that mean "is not an empty string"?

  • ideo (unregistered) in reply to frits
    frits:
    ideo:
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.
    Jaime, is that you?

    Oh, OK. So I guess all Hispanics look alike?

    Went there awfully quick, dincha? Maybe you just like footie, and ur trolling, lulz.

    With regards to the content of your openly combative question, I can't say about all Hispanics, since I haven't met them all yet, but you do look a bit like Jaime to me...

    And this guy has a better point.

  • (cs) in reply to ideo
    ideo:
    frits:
    ideo:
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.
    Jaime, is that you?

    Oh, OK. So I guess all Hispanics look alike?

    Went there awfully quick, dincha? Maybe you just like footie, and ur trolling, lulz.

    With regards to the content of your openly combative question, I can't say about all Hispanics, since I haven't met them all yet, but you do look a bit like Jaime to me...

    And this guy has a better point.

    It was a yoke, man. A failed joke, too, because that guy isn't even hispanic. Shit.

  • ideo (unregistered) in reply to frits
    frits:
    ideo:
    frits:
    ideo:
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.
    Jaime, is that you?

    Oh, OK. So I guess all Hispanics look alike?

    Went there awfully quick, dincha? Maybe you just like footie, and ur trolling, lulz.

    With regards to the content of your openly combative question, I can't say about all Hispanics, since I haven't met them all yet, but you do look a bit like Jaime to me...

    And this guy has a better point.

    It was a yoke, man. A failed joke, too, because that guy isn't even hispanic. Shit.

    Ach! Now I retreat in shame. And I had my dukes up, and everything!

    Better get this thing recalibrated.

  • Zac (unregistered)

    It's comparing params.get(sub.getFieldName().toLowerCase()).getValue().trim() to an empty value.

  • MojoMaster (unregistered) in reply to Anon

    checks if its not empty?

  • Chris (unregistered) in reply to Anon

    The ! in C# typically means to flip the boolean of the result, so in this case that would be saying if the statement in the parenthesis is false (.equals, i presume, returns a boolean TRUE or FALSE), then the result should be true.

    That said...wow, that's a fugly way of writing something...

  • Chris (unregistered) in reply to Anon

    Do'h...just realized the featured comment is getting tons of reply. Kind of a bad BBS system...

  • Mikolaj (unregistered) in reply to Anon

    !"".equals(test) - it's a null-safe way of checking whether test is not an empty string.

  • Zephod (unregistered)

    Hell, if we call it coding, we'd better make sure the stuff isn't readable, eh?

  • negated string comparison (unregistered) in reply to Anon

    !"".equals seems like a really bad way to check for a null string. But then, this is enterprise code.

  • curtmack (unregistered) in reply to Anon
    Anon:
    For readability:
    if (
    	params.containsKey(sub.getParentField().toLowerCase()) 
    	&& (
    		params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) 
    		|| (
    			"*".equalsIgnoreCase(sub.getReplaceOn()) 
    			&& params.get(sub.getFieldName().toLowerCase()) != null 
    			&& params.get(sub.getFieldName().toLowerCase()).getValue() != null 
    			&& !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim())
    		)
    	)
    	&& params.containsKey(sub.getFieldName().toLowerCase())
    ) {

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    It's a very weird way of testing whether the string being fetched by the monstrosity inside the parentheses is empty barring whitespace.

  • Anon 2 :p (unregistered) in reply to Anon

    Combined with the previous line, it's equivalent to

    !String.isNullOrEmpty(params.get(sub.getFieldName().toLowerCase()).getValue())

    I think

  • Roger Willcocks (unregistered)

    if the key (in case insensitive / always lower case form) is present, and the value is not a null or empty string.

    Man that .NET string.IsNullOrEmpty function would come in handy here.

    Also some temporary variables.

  • Hamy (unregistered) in reply to Anon

    In Java strings, such as "foo" and "bar" are actually objects at some level, so it's perfectly valid to say if ("foo".equals(stringFoo)) (although most people would probably say if (stringFoo.equals("foo"))

  • Hamy (unregistered) in reply to Anon 2 :p

    It doesn't test if the string is null - just that it's not empty

  • Chris (unregistered) in reply to Anon
    Anon:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?
    I'd say
    !"".equals(stuff)
    means something like
    (stuff) != ""
    AFAIK. But I may be mistaken.
  • jumbo (unregistered)

    Yes it checks if the string in empty. Although there is better way to do that.

  • Joe (unregistered) in reply to Anon

    !"".equals(...) verifies that the trimmed String is not empty.

    That is to say, it's equivalent to the Boolean expression:

    !(params.get(sub.getFieldName().toLowerCase()).getValue().trim()).equals("")

  • Dan (unregistered) in reply to Anon

    I guess it just checks that the string is not empty...

    I have to admit that when checking the presence of "*" in a string, I never thought of ignoring the case they used for it! I have just learned something :)

Leave a comment on “The Other If”

Log In or post as a guest

Replying to comment #:

« Return to Article