I have a method that takes an Integer baz as an optional parameter via overloading like so ...
public static void myMethod(String fooBar, Integer baz) {
switch(baz){} // baz gets unboxed, NPE if it was null
if(baz != null) {
// Do something
}
else {
// Do something else
}
}
public static void myMethod(String fooBar) {
myMethod(fooBar, null);
}
However, it's giving me a warning about the else statement saying it's dead code. But when the method is called without baz, baz should just default to null so this should not be dead code. Any explanation as to what I'm doing wrong here? How would baz always be non-null even though I set it to null in the overloaded method?
EDIT: Deleted actual code so my question is easier to read.