Two jar packages and classes with the same package name and class name appear in their own code

Class load order testing

 

testjar1.jar

package com;

public class TestJar {
	public String getVersion() {
		return "v1";
	}
}

 

 

testjar2.jar

package com;

public class TestJar {
	public String getVersion() {
		return "v2";
	}
}

 

 

Project TestJavaLoad

Include

package com;

public class TestJar {
	public String getVersion() {
		return "self";
	}
}

 

Sort by classpath to get three results

 

              

 

Obviously, whoever is in the front will be loaded first and will not be overwritten

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326265514&siteId=291194637