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()
?
In languages that create objects from classes, an object is an instantiation of a class. That is, an object is a member of a given class with specified values rather than variables. For example, in a non-programming context, "bird" could be a class and your pet bird Polly an object of that class.
Every object has a type and the object types are created using classes. Instance is an object that belongs to a class. For instance, list is a class in Python. When we create a list, we have an instance of the list class.
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax: OuterClass outerObject = new OuterClass(); OuterClass.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With