I am looping through a collection of Parameter objects, looking for Parameter.name = "Code". If I can’t find it I default to the first Parameter in the list, as below:
header = WBMessageFactory.getWBMessageDescriptor(Configuration.getWBHeaderIDString());
for (Parameter p : header.getSegment().getParameter()) {
if (p.getName() == "Code") {
String wbCode = raw.substring(p.getStartPosition().intValue(), p.getLength().intValue());
logger.info("Found WB code... " + wbCode);
body = WBMessageFactory.getWBMessageDescriptor(wbCode);
break;
}
}
if (body == null) {
Parameter p = header.getSegment().getParameter().get(0);
logger.error("Could not find Code parameter in Header template, using " + p.getName());
body = WBMessageFactory.getWBMessageDescriptor(raw.substring(p.getStartPosition().intValue(), p.getLength().intValue()));
}
As you can see, I log the Parameter name when I can’t find Code. Occasionally, logging reveals the following:
Could not find Code parameter in Header template, using Code
Can anyone explain what the heck is going on?
The problem is here:
You probably meant to say
The first one compares the string reference, which is almost certainly not what you want. The second one compares the contents of the string.