There's a package in eclipse. The following test class calls the default package method inside the class

Source: Internet
Author: User

1, obtained by the static method of class.

Class Clazz = Class.forName ("class name");//Load the class specified by the passed-in class name into the JVM memory
Method[] methods = Clazz.getmethods ();//method to get all public types of the related class
for (Method method:methods) {
Method.invoke (Clazz.newinstance ());//execute the object's parameterless constructor method to create an instance of the class call method
}
Method method = Clazz.getmethod ("method name");//methods for obtaining the public type of the related class by method name
Method.invoke (Clazz.newinstance ());

2, through the class loader

ClassLoader ClassLoader = This.getclass (). getClassLoader ();//Gets the class loader for the current object
Class clazz1 = Classloader.loadclass ("class name");//load the required class through the class loader

Method[] methods = Clazz1.getmethods ();
for (Method method:methods) {
Method.invoke (Clazz1.newinstance ());
}
Method method = Clazz1.getmethod ("Methods name");
Method.invoke (Clazz1.newinstance ());

There's a package in eclipse. The following test class calls the default package method inside the class

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.