I'm sure this is going to be a head-slapper, but I've been battling with this for a couple days, and am failing to see a problem in the code.
This is a very minimal example of the code, necessary to demonstrate the issue. The code is supposed to parse css styles. I've added comments and println to help visualize the issue. In the "bold" switch case, the boolean is being assigned false, even though it's clear that the value is "bold". (I demonstrate it actually is a 4 character value.)
public class HtmlCssStyle {
public static void main(String[] args) {
var s = new HtmlCssStyle("font-weight:bold;");
System.out.println(s.bold);
}
public Boolean bold = null;
public HtmlCssStyle(String cssStyle) {
Parse(cssStyle);
System.out.println("Bold: " + bold);
}
public void Parse(String cssStyle) {
String[] cssStyles = cssStyle.split(";");
for(String style : cssStyles) {
String[] parts = style.split(":");
String name = parts[0].trim();
String value = parts[1].trim();
switch(name) {
case "font-weight":
System.out.println("bold value: *" + value + "* " + value.length()); // value debug (also demonstrates it is entering case
this.bold = (value == "bold"); // never assigns the Boolean value
break;
}
}
}
}
My output is:
bold value: *bold* 4
Bold: false
false
In contrast, this test code works just fine:
public class test {
public Boolean myBool = null;
public static void main(String[] args) {
System.out.println(new test().myBool);
}
public test() {
String s = "bold";
this.myBool = (s == "bold");
}
}