Hi,
If I have:
1. Account a = api.getAccount();
2. AccountX extends Account;
Then I do:
AccountX x = (AccountX) api.getAccount();
I got runtime class cast exception. Could you explain why?
Printable View
Hi,
If I have:
1. Account a = api.getAccount();
2. AccountX extends Account;
Then I do:
AccountX x = (AccountX) api.getAccount();
I got runtime class cast exception. Could you explain why?
You get a runtime ClassCastException whenever you try and cast something whose runtime type is not what you are casting to (or a subtype of what you are casting to). In your case api.getAccount() returned something that was not an instance of AccountX.