soldieryap
Programmer
sorry that i mess up the question and thanks for all the guys in my previous question > Object Casting Question < i would like to clearly define my question again.
Away from polymorphism or something else, i would like to know is there any solution/function that can cast an Object type instance to its original Type(eg, Dog)?
eg. Dog dog = new Dog();
Object obj = dog();
((XX) obj).sound(); // how i cast it back?
// and i don't expect to use
// ((Dog) obj).sound();
when i wanna find out the original type of the obj, i use obj.getClass().getName(); but what i want is not find out the Class name it actually is instead of casting that Object type (obj) to Dog. just because of some other reason i have to cast it to Object and i have to cast it back now and perform some function only exist on that Class. and i don't want to use ((Dog) obj).sound(); because i may write lots code of "instanceof" just to test out which Class is actually belongs to.
do u guys got what i mean??
thanks for ur notice and sorry for my poor explaination!
if u still don't understand please state it out.
Away from polymorphism or something else, i would like to know is there any solution/function that can cast an Object type instance to its original Type(eg, Dog)?
eg. Dog dog = new Dog();
Object obj = dog();
((XX) obj).sound(); // how i cast it back?
// and i don't expect to use
// ((Dog) obj).sound();
when i wanna find out the original type of the obj, i use obj.getClass().getName(); but what i want is not find out the Class name it actually is instead of casting that Object type (obj) to Dog. just because of some other reason i have to cast it to Object and i have to cast it back now and perform some function only exist on that Class. and i don't want to use ((Dog) obj).sound(); because i may write lots code of "instanceof" just to test out which Class is actually belongs to.
do u guys got what i mean??
thanks for ur notice and sorry for my poor explaination!
if u still don't understand please state it out.