本文介绍了java classloader如何识别重复的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个Java项目,在我的类路径中添加了2个不同的jar. Java类加载器在2个jar中发现了一些重复的类,然后只加载其中一个.

Let us say I have a java project where I have added 2 different jars in my classpath. Java classloader found some duplicate classes in the 2 jar and then only one among them will be loaded.

classloader如何确定classpath中的两个类相同?只是按类Name或packageName.className进行比较,还是比较这些类的每个字节代码?

How does classloader decide that 2 classes in the classpath are same ? Just by class Name or packageName.className Or it compares each byte code of those classes ?

推荐答案

它仅由完全限定的名称(程序包+类名)决定,并加载(通常-取决于类加载器),这是第一个在类上找到的类.类路径.没有字节码比较.

It decides just by fully-qualified name (package + class name), and it loads (in general - depends on classloader), the first class found on the classpath. There is no bytecode comparision.

这篇关于java classloader如何识别重复的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 08:00