Posted: Wed Feb 12, 2014 3:01 am Post subject: RE:Object Typecasting
Yes, you could do that. You could also use the instanceof operator to determine whether the argument is of the correct type. If it isn't, then casting it will generate a ClassCastException.
This is generally considered poor programming practice, and you would be better off designing your code to avoid this kind of scenario. The instanceof operator shouldn't show up in application code, and only very very rarely in library code.