Reflection (2)-3 differences between different types of Loading Methods

Source: Internet
Author: User

Source code:

1 package reflex; 2 3 Public class dog {4 static {5 system. out. println ("loading static modules"); 6} 7 public dog () {8 system. out. println ("execution constructor"); 9} 10}
1 package reflex; 2 3 Import Org. JUnit. test; 4/** 5 * three types of loading methods 6*1. class. forname ("Class Name"): load the class and perform static initialization. 7*2. use the keyword New: load the class, perform static initialization, and execute the Construction Method 8*3. class Name. class: only load classes without static initialization. 9 */10 public class dogreflex {11 @ test12/** 13 * print the result: load the static module 14 */15 public void test1 () throws exception {16 class clazz = Class. forname ("reflex. dog "); 17} 18 @ test19/** 20 * print the result: load the static Module 21 * execute the Construction Method 22 */23 public void Test2 () {24 Class clazz = new dog (). getclass (); 25} 26 @ test27/** 28 * No print result 29 */30 public void test3 () throws exception {31 class clazz = dog. class; 32} 33}

 

Reflection (2)-3 differences between different types of Loading Methods

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.