Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an instance for Class?

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() ?

like image 490
Suresh Atta Avatar asked Aug 13 '15 08:08

Suresh Atta


People also ask

What does creating an instance of a class mean?

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.

What is an instance of a class example?

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.

How do you create an instance of a class in another 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.


1 Answers

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.

like image 79
Konstantin Yovkov Avatar answered Oct 20 '22 06:10

Konstantin Yovkov