machine
machine

Reputation: 295

get possible instance/type of object

I have the problem that a given object could be one of several different objects (like files in a directory, that could be sound, image, text, ...) Is there the possibility to find out the type of the object beside from the 'instanceof' operator? Couse that would result in an endless if - then row ...

Upvotes: 13

Views: 20776

Answers (1)

Joachim Sauer
Joachim Sauer

Reputation: 308131

foo.getClass() gets the java.lang.Class object describing the class of the object.

Upvotes: 22

Related Questions