I have a method that receives a parameter which can be null. I have used instanceof to check the type but if the parameter comes null, instanceof returns null. I have read the documentation and it is how instanceof works. In this case , I want to check the type of the passed parameter even if the value is null.
example
public static void checkType(Object yourObject) {
if(yourObject instanceof String) { // this fails if null passed, even if declared as String
print("You have passed a String");
}
}
What could I do in these cases?
My goal is, that:
String myvar = null;
checkType(myvar);
would print:
"You have passed a String"