I got this question as an assignment:
Packages/Naming
We have created lot of packages and defined classes and interfaces in them. We have also discussed the point we have to remember while naming them. In this assignment we will see how important naming is.
Please change the package names in your previous assignment such that two packages have same name and analyze the result/errors that will be thrown.
My Doubt:
I am unable to think of a way(scenario) to demonstrate what has been asked. Since Java imports are absolute, the situation described in question seem impossible to produce (IMO).
Please help me to demonstrate this thing.
Thanks in advance :)
Yes, if you change the package name you'll need to change the imports as well. If you happen to use Eclipse, there's an easy way to do this. In the Package Explorer view, right click on the package and do Refactor->Rename. It will rename the package and update all relevant imports in other classes.
Here's how it could work:
JavaProjectA
src
com.some.package
ClassA
JavaProjectB
src
com.another.package
ClassA
Fine so far. Each class is unique because of its package structure. However, its possible to create this:
JavaProjectA
src
com.some.package
ClassA
JavaProjectB
src
com.some.package
ClassA
Only one of those ClassA classes will get exported in a jar and used at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With