update ListClassLoader

This commit is contained in:
tursom 2020-08-16 03:50:48 +08:00
parent 7b47f3382a
commit f42934be66

View File

@ -1,23 +1,23 @@
package cn.tursom.core
import java.net.URL
import java.net.URLClassLoader
@Suppress("unused")
class ListClassLoader(url: Array<out URL>, parent: ClassLoader? = null) : URLClassLoader(url, parent) {
private val parentList = ArrayList<ClassLoader>()
val parents: List<ClassLoader> get() = parentList
class ListClassLoader(
//url: Array<out URL>,
parent: ClassLoader = getSystemClassLoader()
) : ClassLoader(parent),
MutableList<ClassLoader> by ArrayList() {
fun addParent(parent: ClassLoader) = parentList.add(parent)
fun removeParent(parent: ClassLoader) = parentList.remove(parent)
val parents: List<ClassLoader> get() = this
fun addParent(parent: ClassLoader) = add(parent)
fun removeParent(parent: ClassLoader) = remove(parent)
override fun findClass(name: String?): Class<*> {
try {
return super.findClass(name)
} catch (e: ClassNotFoundException) {
}
parentList.forEach {
forEach {
try {
return it.loadClass(name)
} catch (e: ClassNotFoundException) {