I want so save "Object" inside an array. I DONT want to save "new Object()" inside an array.
Why? I have 3 big If Statements where i check if a Instance is instanceof SomeClass, e.g.
if (x instanceof String) {
SomeMethod(x, String);
}
I Plan Something like:
Class<?>[] classes = {Object, String, SomeOtherClass};
for (int i = 0; i < 3; i++) {
if (x instanceof classes [i]) {
SomeMethod(x, classes [i]);
}
}
However this is working
Class<?>[] classes = {Object.class, String.class, SomeOtherClass.class};
but then i can't use instanceof any more.
Any Suggestions?
P.S: while searching for this i only found how to save an Instance of a Class inside an array, not the Class itself...
Edit:
at the Position of SomeMethod i want to use a generic Type based on the Class (Object,String).
This does not work with Object.class, String.class.