Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set/Get Bug ?

 
Greg Neef
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see what I am doing wrong here. I'd swear the boolean should be getting set, but for some reason it is not.


The output is:
parms.getString( "vhs" ) = yes video.inVHS() = false

[ November 13, 2003: Message edited by: Greg Neef ]

Marilyn removed just a couple more lines of code.
[ November 13, 2003: Message edited by: Marilyn de Queiroz ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this not a case of the dreaded "==" comparison on Objects (in this case String objects)?
-Barry
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1817
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try outputting the *exact* condition you're testing:
out.println( parms.getString( "vhs" ) == "yes" );
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm at work so I can't check my version of this task but: isn't it important to remember here that if you have 2 Strings s1 and s2,
if ( s2 == s1)
asks whether both s1 and s2 point to exactly the same space in the computer's memory, NOT whether the 2 strings contain the same text.
[ November 14, 2003: Message edited by: Elouise Kivineva ]
[ November 14, 2003: Message edited by: Elouise Kivineva ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe one of the author's here had a signature saying something along the lines of "Using "==" to compare Strings is like running with scissors."
 
Greg Neef
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DOH!
This is why coding a 11PM is not a good idea, no matter how much coffee you drink. Thanks all!
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runs with Scissors is my Indian name.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jason adam:
I believe one of the author's here had a signature saying something along the lines of "Using "==" to compare Strings is like running with scissors."

That would be Ernest Friedman-Hill, bartender, author, and the Henny Youngman of Java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic