hardcore java 学习笔记1

来源:互联网 发布:avtaobaocom淘宝网址 编辑:程序博客网 时间:2024/05/29 17:57

       RTTI(runtime type identification),运行时类型识别。不管我们有没有意识到,这个技术都在JVM中广泛的应用着。每当我们使用getClass(),我们就是在使用RTTI。

      

而cast方法也是以RTTI为基础建立的。

 

This code shows how to create an object of a subclass,cast it to its base class,and then cast it back to the subclass . RTTI works in the background to ensure that your casting is always legal; in other words,an object can safely be cast only to its own type, or to a type that it is inherited from.