The best approach to resolving name conflicts between names between namespaces

I am facing a problem with a helper class I'm working on to translate between two classes with the same name. Both classes are beyond my control, so I can’t just rename them.

My main options include a full namespace declaration for at least one of the types:

import com.myco.second.long.package.namespace.MyObject; public class MyObjectConvertor { MyObject transform(com.myco.first.long.package.namespace.MyObject o) {} } 

Or the reverse approach:

 import com.myco.first.long.package.namespace.MyObject; public class MyObjectConvertor { com.myco.second.long.package.namespace.MyObject transform(MyObject o) {} } 

Or by declaring both namespaces, for a more explicit pattern:

 public class MyObjectConvertor { com.myco.second.long.package.namespace.MyObject transform(com.myco.first.long.package.namespace.MyObject o) {} } 

Is there any other solution that could tidy up these method signatures? I am wondering if some kind of "typedef" style solution is possible in C ++?

+6
source share
1 answer

There is no way to remove signatures; at least one class will need to be referenced by the full class name.

And in your particular case, I would even say: do not import any of these classes, use version 3 in the source code, so that everyone is fully aware that your conversion classes with the same name are defined in different packages.

+8
source

Source: https://habr.com/ru/post/891957/


All Articles