5
I’m creating a Java function that returns the type of the variable and as such, since I’m trying to figure out its type, I have no way to tell the function what type of variable to expect.
What I’m trying to build is this:
public String getVarType(AnyType var){
if (var instanceof ArrayList) {
return "ArrayList";
}
if (var instanceof String) {
return "String";
}
}
How can I set in the parameters for the function to expect any kind?
I know, but this method can return a fatal error if I forget to validate some kind of variable. That’s why I’m resorting to
if
in order to have recourse toelse
– CIRCLE