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

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.

主站蜘蛛池模板: 和硕县| 黄平县| 牟定县| 高雄县| 稻城县| 武强县| 即墨市| 兰州市| 扬州市| 名山县| 阳原县| 汉川市| 祁门县| 阿坝县| 鹿泉市| 平度市| 荔浦县| 奉节县| 沙雅县| 达州市| 桂林市| 东源县| 巴彦淖尔市| 甘肃省| 临夏市| 鹤山市| 潢川县| 靖安县| 镇江市| 塔城市| 云南省| 阳江市| 洞头县| 和田市| 三穗县| 泗洪县| 加查县| 左贡县| 汝阳县| 伊金霍洛旗| 河北区|