Child question + operators confusion

C

cliveswan

Hi All,

Eventually managed to get the operators working, well sort of.
I still do not understand the 'logic' bit.

Trying to get an if ..else to work, any help appreciated.

/// This line does not work??
// I do not understand why

String basem = ("BB");
String grd = "GG";
String spfy = "99";

if ( page9.getEntryFloorToDwelling() != basem &&
page9.getEntryFloorToDwelling() != grd &&
page9.getEntryFloorToDwelling() != spfy ){
validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
}

///This line does work (horray)
if ( page9.getEntryFloorToDwelling() == " " ) {
validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
}
 
E

Eric Sosman

Hi All,

Eventually managed to get the operators working, well sort of.
I still do not understand the 'logic' bit.

Trying to get an if ..else to work, any help appreciated.

/// This line does not work??
// I do not understand why

String basem = ("BB");
String grd = "GG";
String spfy = "99";

if ( page9.getEntryFloorToDwelling() != basem &&

This test asks the question: "Is the String object
returned by the method the exact same String object that
basem refers to?" The question you should be asking
is instead: "Does the String object returned by the
method have the same content as the String object that
basem refers to?" For the latter question, use the
..equals() method of the String class.

(How can two Strings have the same content and yet
not be the same String? Easy: My wallet contains ten
rubles and your wallet contains ten rubles, yet they
are different wallets. If you think not, send me your
wallet -- which is, of course, my wallet!)
page9.getEntryFloorToDwelling() != grd &&
page9.getEntryFloorToDwelling() != spfy ){
validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
}

///This line does work (horray)
if ( page9.getEntryFloorToDwelling() == " " ) {
validationResultPage9.addError("EntryFloorToDwelling", "Entry floor");
}

You only think this line "works" because you haven't
tested it adequately.

Clive, it seems to me -- no offense intended -- that
you should spend more time with a Java textbook than you
have spent thus far. The questions you ask suggest that
you have not yet even grasped the basics of the language,
much less mastered them. Usenet is not a good vehicle
for wholesale inculcation of basic knowledge, so I suggest
you try to learn the ABC's from a more effective source.
Come back to Usenet when you are puzzled by a particular
point in your studies, but don't use it as a substitute
for study.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top