Somjit
Somjit

Reputation: 2772

What happens when a local jar contains class file with the same name as one in the java library?

My particular case deals with a class called Point2D thats in a local jar that i included in my project , however ,i also noticed that java has its own Point2D inside java.awt.geom . I understand that for this particular case , since i dont import java.awt.geom , so when i write Point2D it will be from my own package ? But if i did have to import java.awt.geom or be in a position where due to an import , i have similarly named class files in both local jar and java library , what will happen then ?

Upvotes: 0

Views: 70

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279970

As long as the package names are different you can reference both with their fully qualified class names

java.awt.geom.Point2D jdkPoint2d = new ...;
com.mycompany.geometries.Point2D ourPoint2d = new ...;

You can also import one of them and use its simple class name and use the fully qualified class name of the other.

Upvotes: 5

Related Questions