적절한 클래스 로더의 구현은 것입니다 : 클래스가 이미로드 된
- 확인합니다.
- 일반적으로 상위 클래스 로더에게 클래스를로드하도록 요청하십시오.
- 클래스 경로에서 클래스를 찾으려고 시도합니다.
ClassLoader.loadClass의 기본 구현은 같은 :
protected synchronized Class<?> loadClass(String name, boolean resolve) {
// First, check if this class loader has directly defined the class or if the
// JVM has initiated the class load with this class loader.
Class<?> result = findLoadedClass(name);
if (result == null) {
try {
// Next, delegate to the parent.
result = getParent().loadClass(name);
} catch (ClassNotFoundException ex) {
// Finally, search locally if the parent could not find the class.
result = findClass(ex);
}
}
// As a remnant of J2SE 1.0.2, link the class if a subclass of the class
// loader class requested it (the JVM never calls the method,
// loadClass(String) passes false, and the protected access modifier prevents
// callers from passing true).
if (resolve) {
resolveClass(result);
}
return result;
}
일부 클래스 로더 구현 것, 예를 들어 다른 비 부모 클래스 로더 (은 OSGi, 클래스 로더의 그래프에 위임하는 위임 패키지에 의존), 일부 클래스 로더 구현은 위임하기 전에 로컬 클래스 경로에서 클래스를 찾습니다.
사실이 아닙니다. http://stackoverflow.com/a/245038/632951에 설명 된대로 많은 클래스로드 모델이 있습니다. "적절하다"고 말하는 것은 모델 중 하나 일뿐입니다. 다른 모델은 실제로 이러한 방식으로 구현되지 않습니다. – Pacerier
맞습니다. 답은 너무 규범 적입니다. 느슨한 언어를 추가하고 클래스 로더가 다른 시나리오를 추가했습니다. 의견을 보내 주셔서 감사합니다. –