Java ClassLoader delegation model?

前端 未结 6 1510
悲哀的现实
悲哀的现实 2021-02-01 08:35

When calling loadClass() on a ClassLoader, does the ClassLoader first check if the class has been loaded, or does it immediately delegate this check to

6条回答
  •  囚心锁ツ
    2021-02-01 09:22

    The Java API is correct.

    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.

    From the Java Classloading Mechanism -

    When loading a class, a class loader first "delegates" the search for the class to its parent class loader before attempting to find the class itself.

提交回复
热议问题