What does this block of code do?

后端 未结 6 983
鱼传尺愫
鱼传尺愫 2021-01-24 13:19

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

Player player = (Player) sender;
6条回答
  •  抹茶落季
    2021-01-24 13:43

    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.

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

提交回复
热议问题