Creating an instance for Class?

2019-04-28 14:16发布

Looking at source code of Integer class, just stumble at this below line

Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");

And getPrimitiveClass is a native method.

 static native Class getPrimitiveClass(String name);

Why it became a native method ? really want to know.

How one can create an instance for Class ?? Does that differs with normal way of creating instance for ex : Ex e = new Ex() ?

1条回答
男人必须洒脱
2楼-- · 2019-04-28 15:07

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);

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.

查看更多
登录 后发表回答