Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1012789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:59:56+00:00 2026-05-16T09:59:56+00:00

The classes: public interface Inter { …some methods… } public class Impl implements Inter

  • 0

The classes:

public interface Inter {
  ...some methods...
}

public class Impl implements Inter {
  ...some implementations...
}

The issue is that for some freaky reason, I have to load the interface Inter with child ClassLoader and the implementation class Impl with parent ClassLoader.

In this case I will get NoClassDefError, because the parent ClassLoader that is trying to load the implementation Impl doesn’t know about the interface Inter that was loaded in child ClassLoader.

Is there any way of loading the implementation with child ClassLoader (context ClassLoader) ? Or may be I need to write some custom ClassLoader to load both of them (by breaking the delegation rule) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:59:56+00:00Added an answer on May 16, 2026 at 9:59 am

    The issue is that for some freaky
    reason, I have to load the interface
    Inter with child ClassLoader and the
    implementation class Impl with parent
    ClassLoader.

    I cannot fathom why the child classloader must load the interface, while leaving the parent classloader to load the implementation. This is bound to cause trouble, for there is no mechanism within the class-loading mechanism utilized by the JVM, to defer loading of classes to a child classloader. The usual mechanism of implementing the classloading behavior in the JVM is defined in the API documentation of the ClassLoader class:

    The ClassLoader class uses a
    delegation model to search for classes
    and resources. Each instance of
    ClassLoader has an associated parent
    class loader. When requested to find a
    class or resource, a ClassLoader
    instance will delegate the search for
    the class or resource to its parent
    class loader before attempting to find
    the class or resource itself. The
    virtual machine’s built-in class
    loader, called the “bootstrap class
    loader”, does not itself have a parent
    but may serve as the parent of a
    ClassLoader instance.

    One can write a custom classloader, by extending the ClassLoader class and overriding the loadClass() method. Extending this method allows to you to change the class loading delegation in either of the two ways:

    • Parent-first: Get the parent classloader to load the class first. This usually is a transitive behavior – most parent classloaders will defer loading to their parent, and so on, until the bootstrap classloader (the root) is reached in the classloader hierarchy. If the parent classloader fails to load the class, the child attempts to load it. An eventual failure in loading the class should result in a ClassNotFoundException being thrown.
    • Parent-last: The custom classloader attempts to load the class first, before delegating to the parent. The parent classloaders are used only when the child fails in its attempt to load the class.

    Most classloaders are implemented as parent-first classloaders. This is due to the fact that the delegation mechanism is able to traverse the tree in the upward direction but not in the downward direction.

    If you really wish to delegate loading and finding of classes to child classloaders in the hierarchy, you will have to manage references to them in the custom classloader for the parent. This is not easy, and is usually not done at all except for very exceptional circumstances since it very easy to end up with the dreaded ClassNotFoundException and NoClassDefFoundError as one must be careful to load only the required classes from the child classloaders, while the rest must always be deferred to the parent (unless I’m mistaken, the feature of shared libraries in certain Java EE containers are implemented this way).

    Having said that, the ideal solution would be to attempt loading both the interface and the implementation classes in the parent classloader, and rely on the delegation mechanism to ensure that the classes are visible to both the classloaders; the parent can “see” classes loaded by itself, and the child can “see” the parent’s classes.

    PS: Don’t forget to use AccessController.doPrivileged when loading and defining classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface, and some classes that inherit from it. public interface IFoo
I have the following classes: public interface Emailer {} @Named public class RealEmailer implements
I have the classes below: SuppliersRepository.cs (with the interface defining the method): public class
Say I have an interface and some classes: public interface IPanel<ComponentType extends Component> {
I have the following classes defined: public interface Thingy { ... } public class
Consider that classes public class Category { } public class Product { } public
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
If I have this classes: public interface IBinaryCalculator{ double addition(double numb1, double numb2); }
For a better understanding of my question, see the following classes: public interface Invoker<R>
classes: public abstract class BaseHolidayPackageVariant { private Integer variantId; private HolidayPackage holidayPackage; private String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.