So I've done a some readings on NullPointerExceptions in Java but I'm still not really understanding it completely.
why does this work?
if ((department != null && department.equals("COMP")) || (department != null && department.equals("COMM")))
{
this.department = department;
}
and also another method that worked was when I first checked for != null and then did a second nested if statement to then check for "COMP" or "COMM".
compared to the above, how come this one doesn't work?
if (department != null || department.equals("COMP")) || department.equals("COMM")))
{
this.department = department;
}
Like most, I don't like having found a solution by accident but not really understanding why it's a solution. I'm still very new to programming so I'm trying to understand what's actually happening underneath the hood. I understand things the easiest when given a metaphor to compare with, it'd really help if someone can explain it for me that way ><;;
Thank you guys very much!