I was trying to find out how to determine which class a given object instantiate when it’s in Object[] array. For example:
Object[] array = new Object[]{175, "sss", new Table(), true};
Object obj = array[0]; // hmm... can this be used as an integer or maybe as a string?
Is it even possible?
You can call
getClass()to find out the class of a particular object, or you can useinstanceofto check a specific type:Normally having to do a lot of this indicates a weakness in your design though – you should try to avoid needing to do this.