Casting variables in Java

前端 未结 5 1658
野性不改
野性不改 2020-11-21 23:50

I wonder if anyone could tell me how casting works? I understand when I should do it, but not really how it works. On primitive data types I understand partially bu

5条回答
  •  终归单人心
    2020-11-22 00:33

    Actually, casting doesn't always work. If the object is not an instanceof the class you're casting it to you will get a ClassCastException at runtime.

提交回复
热议问题