我正在阅读下面的文章,但不明白以下段落背后的原因:
Class loaders can opt to load a type early in anticipation of eventual use. If this strategy is chosen, the class loader must not report any problem (by throwing a subclass of java.lang.LinkageError) encountered during loading until the type's first active use. In other words, a type must appear to be loaded only when needed.
这背后有什么具体原因吗?在该类型首次使用期间可能会出现什么类型的问题以及为什么需要专门报告?我对 JVM 的了解有限,因此我们将不胜感激任何其他资源。
http://www.developer.com/java/other/article.php/2248831/Java-Class-Loading-The-Basics.htm
最佳答案
如果加载程序预取了一组相关的类,但有问题的类从未实际使用过,那么抛出错误将没有用处或没有必要。
作为可能发生的问题类型的示例,类级别变量声明中的格式错误的正则表达式可能会在加载时导致问题。或者可能存在依赖关系问题,缺少其中一个导入。
那么,如果从未使用过该类,为什么会抛出错误?
关于java - 为什么 JVM 类加载器必须在第一次主动使用之前才报告问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35419616/