In a fairly performance critical part of an application that I'm working on, I have an option of using either the instanceof operator, or the Class.isInstance() method.
I can use either approach, but the latter makes the code a bit cleaner/more elegant
If we assume that the design for either approach will have the exact same performance, aside from the instance check, should I prefer one over the other?
To make it more concrete, I am wondering if one of these will be more perform better than the other:
public boolean isAString(Object o) {
return o instanceof String;
}
public boolean isAString(Object o) {
return String.class.isInstance(o);
}
And no, I don't actually plan on using this actual method.