Ak triedy B
a C
rozširujú triedu A
a mám objekt typu B
alebo C
, ako môžem určiť, ktorého typu je inštanciou?
Môžete použiť:
Object instance = new SomeClass();
instance.getClass().getName(); //will return the name (as String) (== "SomeClass")
instance.getClass(); //will return the SomeClass' Class object
HTH. Ale myslím si, že väčšinou nie je dobré používať to pre control flow alebo niečo podobné...