该代码块的作用是什么? [英] What does this block of code do?

查看:93
本文介绍了该代码块的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定这是什么意思或在做什么,有人可以详细说明吗?

I'm not quite sure what this means or whats it doing, Could some one elaborate?

Player player = (Player) sender;

推荐答案

它获取发送者引用的对象,并尝试将其强制转换为Player类型. Java对象是强类型的,这意味着您必须声明对象的类型.

It takes the object referenced by sender, and attempts to cast it into the type Player. Java objects are strongly typed, which means you have to declare the type of the object.

如果发件人引用的对象不能转换为Player对象,则将为InvalidCast抛出异常.

If the object referenced by sender cannot be cast to a Player object, than an exception will be thrown for an InvalidCast.

这篇关于该代码块的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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