为类创建实例? [英] Creating an instance for Class?
本文介绍了为类创建实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看Integer类的源代码,只需在下面的行中跳过
Looking at source code of Integer class, just stumble at this below line
Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
并且 getPrimitiveClass
是一种本地方法。
And getPrimitiveClass
is a native method.
static native Class getPrimitiveClass(String name);
为什么成为本地方法?真的想知道。
Why it became a native method ? really want to know.
如何创建类
的实例?这与创建ex: Ex e = new Ex()
的常规方法不同吗?
How one can create an instance for Class
?? Does that differs with normal way of creating instance for ex : Ex e = new Ex()
?
推荐答案
方法定义上面的注释说:
The comment above the method definition says:
/*
* Return the Virtual Machine's Class object for the named
* primitive type.
*/
static native Class getPrimitiveClass(String name);
由于(至少,Sun的)虚拟机是在C中实现的,是该方法的原因是 native
。
Since the (at least, Sun's) Virtual Machine is implemented in C, then I would assume that this is the reason for the method being native
.
这篇关于为类创建实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文