简体   繁体   中英

How to access class loaded by classloader in lower hierarchy from class in higher up hierarchy

Probably the heading is not very clear. Here is the problem/scenario.

Class A is loaded by ClassloaderA Class B is loaded by ClassloaderB

ClassloaderB is in lower hierarchy than ClassloaderA so I'm aware that class A can not access class B.

Is there any way at all that class A can access class b. (Say if Class A accesses ClassloaderB and asks to give Class B then access it's methods using reflection)

Is this possible?

Its done by default, depending on classloader policy (parent-first, parent-last).

Parent-first:
Classloader B (child) tries to find class X so it asks first a parent (ClassloaderA) if it has that class on classpath and load that class. If parent has access to that class, than the parents version is used, if not child tries to find the class on childs classpath.

Parent-last
ClassloaderB (child) looks the class on child classpath, if not found parent is asked to load find the class on classpath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM