Java record-89-java. lang. Class

Source: Internet
Author: User

Java record-89-java. lang. Class
As we all know, Java has an Object class, which is the root inheritance of all Java classes. It declares several methods that should be rewritten in all Java classes: hashCode (), equals (), clone (), toString (), getClass (), etc. GetClass () returns a Class object. The Class class is very special. It inherits from the Object like the general classes. In fact, it is used to express the classes and interfaces when Java is running. It is also used to express enum, array, primitive Java types (boolean, byte, char, short, int, long, float, double) and keyword void. When a class is loaded, or when the defineClass () of the loader (Class loader) is called by JVM, JVM automatically generates a Class object. In the Java JDK source code, we can see that the Constructor of the Class is private, and the comments are: Constructor, Only the Java Virtual Machine creates Class objects. Only the Java Virtual Machine can create Class objects. The Class contains many native methods, that is, local methods, which are implemented by C or C ++ instead of Java. Class is the origin of Reflection. For any Class you want to explore, you can only generate a Class object for it first. Then, the latter can evoke dozens of Reflection APIs. Java allows us to generate the corresponding class object for a Class in multiple ways: 1. use getClass (); (each class has this function) 2. use Class. getSuperclass (); 3. use static method Class. forName (); (most commonly used) 4. application. class syntax (Class str = String. class) 5. use the TYPE Syntax of primitive wrapper classes (Class c1 = Integer. TYPE)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.