简体   繁体   English

JVM中的类类[Venner's Book]

[英]Class class in JVM [Venner's Book]

I read in Venners book that When a new Type is loaded by the virtual machine , the virtual machine instantiates a new instance of " Class " and associates this instance with the new loaded type in some way ... 我在Venners的书中读到,当虚拟机加载新类型时 ,虚拟机将实例化“ ”的新实例,并以某种方式将此实例与新加载的类型相关联...

now my question : Does The VM instantiates an object of Type " Class " for the " Class " Type itself as being a class which is a type of the three reference types ? 现在我的问题:请问VM实例类型 ”的对象为“ 类型本身为一类,这是一个类型的三个参考类型的?

Another Question : When a Class B extends another class A (A is parent) Does the class B info in the method Area include All inherited features of the parent or just specific for it (B) and the Super Class pointer in it's class information is sufficient ? 另一个问题:当类B扩展了另一个类A(A是父类)时,方法Area中的类B信息是否包含父类的所有继承特性或仅特定于父类(B),并且其类信息中的超类指针为足够了吗? or it's Implementation specific ? 还是特定于实现?

Thanks 谢谢

Yes, there is an instance of type java.lang.Class which represents the type java.lang.Class itself. 是的,有一个类型java.lang.Class的实例,它表示类型java.lang.Class本身。

You get access to such a Class instance in two ways, by calling getClass() on an instance of the class or via class literal. 您可以通过两种方式访问​​此类Class实例,方法是在该类的实例上调用getClass()或通过类文字。

Class<?> str = "foo".getClass(); // represents type String
Class<?> cls = str.getClass(); // represents type Class

or 要么

Class<?> str = String.class; // represents type String
Class<?> cls = Class.class; // represents type Class

Obviously, you can't get the Class instances representing the primitive types or void by calling getClass() on an object, but there are still two ways 显然,您无法通过在对象上调用getClass()来获得表示原始类型或voidClass实例,但是仍然有两种方法

Class<?> intType = Integer.TYPE; // represents type int
Class<?> voidType = Void.TYPE; // represents type void

or 要么

Class<?> intType = int.class; // represents type int
Class<?> voidType = void.class; // represents type void

The existence of a memory region named “method area” is already an implementation detail, so the way the data is organized within it, is even more implementation specific. 名为“方法区域”的内存区域的存在已经是一个实现细节,因此其中的数据组织方式甚至更加具体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM