MCPcopy Create free account
hub / github.com/JavaCourse00/JavaCourseCodes / main

Method main

01jvm/XlassLoader.java:12–30  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

10public class XlassLoader extends ClassLoader {
11
12 public static void main(String[] args) throws Exception {
13 // 相关参数
14 final String packageName = "lib";
15 final String className = "Hello";
16 final String methodName = "hello";
17 // 创建类加载器
18 ClassLoader classLoader = new XlassLoader();
19 // 加载相应的类
20 Class<?> clazz = classLoader.loadClass(packageName + "." + className);
21 // 看看里面有些什么方法
22 for (Method m : clazz.getDeclaredMethods()) {
23 System.out.println(clazz.getSimpleName() + "." + m.getName());
24 }
25 // 创建对象
26 Object instance = clazz.getDeclaredConstructor().newInstance();
27 // 调用实例方法
28 Method method = clazz.getMethod(methodName);
29 method.invoke(instance);
30 }
31
32 @Override
33 protected Class<?> findClass(String name) throws ClassNotFoundException {

Callers

nothing calls this directly

Calls 3

printlnMethod · 0.80
getNameMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected