Java - 你能把一个对象转换成一个不扩展的类吗? [英] Java - Can you cast an object into a class it doesn't extend?

查看:158
本文介绍了Java - 你能把一个对象转换成一个不扩展的类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一种提出同样问题的方法是,给定2类A和B,它是同义词:对象A可以转换成B,对象A是B的后代?

Another way to ask the same question is, given 2 classes A and B, is it synonymous to say: "Object A can be cast into B" and "Object A is a descendant of B"?

感谢,

JDelage

strong>澄清这个问题,使A和B都更清楚。

Clarified the question to make it clearer that both A and B are classes.

推荐答案

将对象转换为不扩展的类。 - 不,你不能。

"Java - Can you cast an object into a class it doesn't extend?" - No, you can't.

基本上,说:对象A可以转换成B,对象A是B的直接后代? - 是的。在A是实现接口B的类的情况下。

"Basically, is it synonymous to say: "Object A can be cast into B" and "Object A is a direct descendant of B"?" - Yes. Plus in the case when A is of a class implementing interface B.

这篇关于Java - 你能把一个对象转换成一个不扩展的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆