think in java笔记:RTTI-Runtime type information
来源:互联网 发布:博源基金会 知乎 编辑:程序博客网 时间:2024/05/21 15:08
RTTI-Runtime type information
To understand how RTTI works in Java, you must first know how type information is
represented at run time. This is accomplished through a special kind of object called the
Class object, which contains information about the class. In fact, the Class object is used to
create all of the “regular” objects of your class. Java performs its RTTI using the Class
object, even if you’re doing something like a cast. The class Class also has a number of other
ways you can use RTTI.
译:
为了懂得RTTI是怎么工作的,你必须type信息是如何在运行时候表示的。这个是通过一个特殊的对象Class实现的,这个对象保存着这个class的信息。实际上,Class对象是用来创建所有正常类型的对象。Java通过Class对象来执行RTTI,即使你看起来是在做cast操作。Class这个class还有一些可以使用RTTI的方式。
(class VS Class : class是静态的引用,Class是用在实例化之后getClass之后得到的,两个都可以获取对象的信息.)
It’s important to realize that there’s nothin g magic about reflection. When you’re using
reflection to interact with an object of an unknown type, the JVM will simply look at the
object and see that it belongs to a particular class (just like ordinary RTTI). Before anything
can be done with it, the Class object must be loaded. Thus, the .class file for that particular
type must still be available to the JVM, either on the local machine or across the network. So
the true difference between RTTI and reflection is that with RTTI, the compiler opens and
examines the .class file at compile time. Put another way, you can call all the methods of an
object in the “normal” way. With reflection, the .class file is unavailable at compile time; it is
opened and examined by the runtime environment.
译:
我们需要知道反射是没有很神奇的东西。当你使用反射来于一个不知道类型的object操作时,JVM将会寻找它所对应的class。在任何东西可以做之前,Class对象必须已经加载。即.class文件必须存在,不论是在本地或者远程机器上。所以RTTI和反射不同的地方就是:RTTI是只能反射出来编译时的所有类型,但是反射可以知道实际运行过程中所有的类型。
- think in java笔记:RTTI-Runtime type information
- Thinking in Java笔记:Runtime Type Information
- C++ typeid 与RTTI(Runtime Type Information)
- C++中的RTTI(runtime type information) 机制
- RTTI(runtime type information Identification) 运行时类型识别
- C++ - RTTI(RunTime Type Information)运行时类型信息 详解
- RTTI (Runtime Type Identification)
- RTTI(Runtime Type Identification)
- Think in java 笔记
- think in java 笔记
- Think in java笔记
- think in java 笔记
- Think in java 笔记
- Think In Java 笔记
- Think in Java 笔记
- Think in Java笔记
- 关于runtime type information
- 三十三、RTTI(runtime type information)、dynamic_cast运算符、typeid运算符、type_info
- easyui的datagrid使用小技巧
- HTML基础之标签篇(二)
- c/c++练习--02
- 关于在windows7系统下,win+上下左右组合键失效的问题
- JAVA多态学习笔记
- think in java笔记:RTTI-Runtime type information
- 【疯狂Java】Java基础1
- 化装晚会(costume)
- js 如何判断前三位是否为数字
- FIR一个免费的App托管平台
- String和StringBuffer的区别
- HDU Problem 2955 Robberies 【01背包】
- java文件读写操作
- 图的深度遍历