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