官术网_书友最值得收藏!

Type casting

Type casting is a way to check the type of an instance and/or deal with that instance as if it is a different superclass or subclass from somewhere else in its class hierarchy. There are two types of operator to check and cast types as the following:

  • Type check operator (is): This checks whether an instance is of a definite subclass type.
  • Type cast operator (as and as?): A constant or variable of a definite class type may refer to an instance of a subclass under the hood. If this is the case, we can try to downcast it to the subclass type with as.

Type safety, type inference, annotation, aliases and type casting will be covered in detail in Chapter 3, Types and Type Casting.

主站蜘蛛池模板: 大庆市| 永清县| 廊坊市| 虹口区| 沿河| 建昌县| 南昌县| 神农架林区| 恩施市| 华安县| 涞水县| 施秉县| 文成县| 左云县| 汕头市| 尼勒克县| 定西市| 博客| 礼泉县| 中牟县| 容城县| 广安市| 永吉县| 美姑县| 晋中市| 安阳市| 西畴县| 塘沽区| 苍溪县| 祥云县| 潢川县| 浪卡子县| 涞水县| 华坪县| 贡觉县| 广汉市| 新密市| 化德县| 东丰县| 安国市| 老河口市|