jeudi 16 avril 2015

Passing Null Integer as Parameter


Vote count:

2




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) {
// code here
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?



asked 3 mins ago


1 Answer



Vote count:

-1




you call the method only without using baz as parameter. so the warning would be ok imho.



answered 44 secs ago

duffy356

1,727





Passing Null Integer as Parameter

Aucun commentaire:

Enregistrer un commentaire