Java rules for casting

后端 未结 6 646
长发绾君心
长发绾君心 2020-12-01 03:25

When can a certain object be cast into another object? Does the casted object have to be a subtype of the other object? I\'m trying to figure out the rules...

6条回答
  •  臣服心动
    2020-12-01 03:47

    You can cast if the runtime type of an object is a subtype of what you're trying to cast it into.

    EDIT:

    Yes, the object that you're trying to cast will need to implement the interface in order for you to cast it successfully.

提交回复
热议问题