From 15fdd1a09289c5b34307a92287a6cf85b40b8b83 Mon Sep 17 00:00:00 2001 From: jaywcjlove Date: Thu, 17 Nov 2022 00:55:42 +0000 Subject: [PATCH] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0=20java=E5=8F=8D?= =?UTF-8?q?=E5=B0=84:white=5Fcheck=5Fmark:=20(#103)=2038453c5e315ec45a522e?= =?UTF-8?q?c55254f88f320b018601?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/java.html | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/java.html b/docs/java.html index 2757bef7..28124981 100644 --- a/docs/java.html +++ b/docs/java.html @@ -42,7 +42,7 @@

该备忘单是针对 Java 初学者的速成课程,有助于复习 Java 语言的基本语法。

入门

Hello.java

public class Hello {
@@ -964,6 +964,23 @@
   System.out.println("always printed");
 }
 
+

反射

+
/**
+* 利用反射动态加载依赖库
+* java9及以上版本可用
+* @param jar jar文件
+*/
+Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+method.setAccessible(true);
+MethodHandle addURL = lookup.unreflect(method);
+URL url = jar.toURI().toURL();
+URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {url});
+addURL.invoke(urlClassLoader, url);
+//java8
+Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+method.setAccessible(true);
+method.invoke(classLoader, url);
+

util工具类

  • ArrayDeque 提供 resizable-array 并实现 Deque 接