Java run-Time type authentication

Source: Internet
Author: User

Run-time type identification? RTTI?

If we have a reference to a base class, this reference can also be used as a reference to the subclass, and now we want to know what the type of reference is.

When there is a lot of information missing from the subclass to the base class, such as having a human object that can be seen as an object in a universal sense, it can also become an object, but we don't know if the object is human.

Rtti is exactly the type of object that is recognized during operation.

If you encounter a particular programming problem, you need to know the specific type of reference to solve the problem.

A class object is required for the generation of the object, and forname (arg0) can obtain the object's class object, resulting in an instance of the class.

The Java compiler does not allow downward auto-conversions unless explicitly specified.

Circle C = (circle) b;

The keyword instanceof tells us that an object is not an instance of a particular class.

It can be used for checking down when converting.

Isinstanceof () can be used directly on object instances

The class object is important, here

Rtti and reflection mechanism

Java run-Time type authentication

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.