1 / 10

第十章 类型检查

第十章 类型检查. 运行时类型识别 (RTTI) 的概念 : 当只有一个指向对象基类的引用时 ,RTTI 机制可以让你找出这个对象的确切类型. 为什么需要 RTTI. 复习一下多态和向上转型 例 :Shapes.java. Class 对象. 理解 RTTI 在 Java 中的工作原理 例 :SweetShop.java. 类型转换前先做检查. RTTI 的形式包括 : 传统的类型转换 代表对象的类型的 Class 对象 关键字 instanceof 例 :AssociativeArray.java 例 :PetConunt.java

mark-olsen
Télécharger la présentation

第十章 类型检查

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第十章 类型检查

  2. 运行时类型识别(RTTI)的概念: 当只有一个指向对象基类的引用时,RTTI机制可以让你找出这个对象的确切类型.

  3. 为什么需要RTTI • 复习一下多态和向上转型 • 例:Shapes.java

  4. Class 对象 • 理解RTTI在Java中的工作原理 • 例:SweetShop.java

  5. 类型转换前先做检查 • RTTI的形式包括: • 传统的类型转换 • 代表对象的类型的Class对象 • 关键字instanceof 例:AssociativeArray.java 例:PetConunt.java 1.使用类字面常量 例:PetCount2.java 2.动态的instanceof 例:PetCount3.java 3.等价性:instanceof与Class 例:FanilyVsExactType.java

  6. RTTI语法 • 首先,需要获得指向适当的Class对象的引用,一种方法是使用字符串和Class.forName()方法 • 例:ToyTest.java • 其次,是方法printInfo()

  7. 反射:运行时的类信息 • 类方法提取器 • 例:ShowMethods.java

  8. 第11章 对象的集合 • 如果一个程序只包含固定数量的且其生命期都是已知的对象,那么这是一个非常简单的程序.

  9. 数组 • 数组是第一级对象 • 例:Arraysize.java • 返回一个数组 • 例:IceCream.java • Array类 • 例: Array2.java • 填充数组 • 例:FillingArrays.java • 复制数组 • 例:CopyingArrays.java • 数组的比较 • 例:CompqringArrays.java • 数组元素的比较 • 例:CompType.java • 数组排序 • 在已排序的数组中查找 • 例:ArraySearching.java • 对数组的小结

  10. 容器简介

More Related