Three ways to get class objects from Java reflection

Source: Internet
Author: User

Package demo01;/** Three ways to get a class file Object * 1. Object Acquisition * 2. Class name gets the static method of the 3.Class class gets*/ Public classReflectdemo { Public Static voidMain (string[] args) throws classnotfoundexception{//1. Object AcquisitionPerson p=NewPerson (); //method of calling the parent class of the person class GetClassClass c=P.getclass (); System. out. println (c); //2. Class name Acquisition//each type, including basic and reference,Class C1=person.class; System. out. println (C1); //static method of the 3.Class class forname (class name of String) package name. Class NameClass C2=class.forname ("demo01. person"); System. out. println (C2); }}

Use = = and equals to compare what they return is true.

Three ways to get class objects from Java reflection

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.