Question

I have created subclasses of XOM Element and would like to use them with Containers such as Set or HashMap. However these require an equals(Object obj) method. I have implemented an algorithm for equality but cannot use it as XOM.Node() declares equals(Object obj) to be final. Is there any way I can easily overcome this? [I could create a wrapper / delegate if that is the only way].

Was it helpful?

Solution

All XOM nodes have equals methods and hashCode methods, as do all Java objects, use them with Containers such as Set or HashMap. The decision to support only identity equality was deliberate, and that's why the equals method is final. The question is why do you need to use a different notion of equality? E.g. if two nodes look the same but are in different positions, or are in different documents, they are usually considered to be different elements. What's the use case for treating them as the same?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top