wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes Set/Get Bug ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Set/Get Bug ?" Watch "Set/Get Bug ?" New topic
Author

Set/Get Bug ?

Greg Neef
Ranch Hand

Joined: Jun 16, 2003
Posts: 82
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 ]

SCJP 1.4
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Is this not a case of the dreaded "==" comparison on Objects (in this case String objects)?
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1744
    
    2
Try outputting the *exact* condition you're testing:
out.println( parms.getString( "vhs" ) == "yes" );
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
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

Joined: May 08, 2001
Posts: 1932
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

Joined: Jun 16, 2003
Posts: 82
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

Joined: Mar 15, 2001
Posts: 1194
Runs with Scissors is my Indian name.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set/Get Bug ?
 
Similar Threads
New to Servlets
Java Polyphormismus BUG (solved: not a bug:-)
hashcode and equals
Retrieving a value ..
Polymorphism Teaser