Reputation: 17118
I have two classes in my app with identicall names, I cannot rename them, on of them is from packageA second from packageB, the name of this class is State, and I have to use it in one place in my program like this:
Map<Integer,Set<org.omg.PortableServer.POAManagerPackage.State>>
is there any way (but using this class) to make this somewhat more readable(to shorten it somewhat)?
Upvotes: 3
Views: 646
Reputation: 15879
If you use the two different State
classes in the same piece of code (*.java file), then the answer is "No", Java does not provide a short hand notation. You must be explicit and include the full package names to remove the ambiguity.
@dantuch has raised an interesting idea, but rather than wrap the class, if you can extend one of them, you can create an empty sub-class of State
that simply defers all of it's implementation to the parent class.
public MyState extends State {
// no implementation required
}
Then you can then refer to MyState
Upvotes: 0
Reputation: 121971
Possibly derive from one of the classes to disambiguate. For example, in POAState.java
:
import org.omg.PortableServer.POAManagerPackage.State;
public class POAState extends State {}
then:
Map<Integer,Set<POAState>> my_map;
Upvotes: 4
Reputation: 9293
Create wrapping class that will have only Set<org.omg.PortableServer.POAManagerPackage.State>
and all the needed Set
methods.
usage in client:
Map<Integer,GoodWrappingSetName>
Upvotes: 0