0

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?

  • Does http://stackoverflow.com/questions/1758241/how-to-use-implementation-loaded-with-different-java-classloader?rq=1 help? – TheConstructor Aug 09 '14 at 15:33

1 Answers1

0

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

rgrebski
  • 2,354
  • 20
  • 29