简体   繁体   English

使用自定义类加载器加载Java运行时和API类

[英]Using a custom class loader to load Java runtime and API classes

Why is it advisable to load the Java Runtime classes and API classes using the default system class loader in Java? 为什么建议使用Java中的默认系统类加载器来加载Java Runtime类和API类? What happens if we load them using our custom class loader? 如果使用自定义类加载器加载它们,会发生什么情况?

One of the criterias for instanceof to be true, is that the two classes must be loaded by the same classloader. instanceof为真的标准之一是两个类必须由同一类加载器加载。 This goes for class casting too. 这也适用于类转换。

This would mean that instances of eg String created by your class loader would not be compatible with the String created by the system class loader. 这意味着您的类加载器创建的String实例与系统类加载器创建的String不兼容。 Are not instances of and cannot be cast to. 不是的实例,也不能投射到。

You probably do not want that. 您可能不想要那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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