-1
public abstract class BaseDataItem<V, T, ThisType extends BaseDataItem<V, T, ThisType>> implements DataItem<V, T> { }

    public abstract class SingularDataItem<Value, T> extends BaseDataItem<Value, T, SingularDataItem<Value, T>> {
    
        @Override
        protected int buildHashCode(HashCodeBuilder builder) {
            return builder.toHashCode();
        }
    
        @Override
        protected boolean isEquivalent(SingularDataItem<Value, T> o) {
            return true; // the parent class already verifies that the object is the same class
        }
    }
Siddharth Kumar
  • 2,672
  • 1
  • 17
  • 24
  • can you provide more detail for the BaseDataItem class? – Shikhar Chaudhary Dec 29 '20 at 04:23
  • @ShikharChaudhary, edited the code snnipet. – Siddharth Kumar Dec 29 '20 at 04:27
  • 1
    Just wanted to mention that it is over-architectured code. It probably makes sense. However the inner class is for instance not static. As _"DataItem"_ reeks of a very pervasive abstraction - of all -, I would start with concrete code, its usage , samples. Try not ever to write such code. – Joop Eggen Dec 29 '20 at 04:41

1 Answers1

0

Well I tried this and the output returned is true that means no matter how many different objects I create for the class Data they all will always be equal and hence I don't know why a code like this is written maybe this code can be explained when looked through the perspective of the domain where this code is used.

public class Test {

public static void main(String[] args) {

    SingularDataItem<String , String> singularDataItem = new Data("testing");
    SingularDataItem<String , String> singularDataItem2 = new Data("testing2");
    System.out.println(singularDataItem.isEquivalent(singularDataItem2));
}}


class Data extends SingularDataItem<String , String>{
private String name;

public Data(String name) {
    this.name = name;
}

public String getName() {
    return name;
}}

abstract class BaseDataItem<V, T, ThisType extends BaseDataItem<V, T, ThisType>> implements DataItem<V, T> {

int buildHashCode(HashCodeBuilder builder){
    return builder.toHashCode();
}

boolean isEquivalent(SingularDataItem<V, T> o){return true;}}

abstract class SingularDataItem<Value, T> extends BaseDataItem<Value, T, SingularDataItem<Value, T>> {

@Override
protected int buildHashCode(HashCodeBuilder builder) {
    return builder.toHashCode();
}

@Override
protected boolean isEquivalent(SingularDataItem<Value, T> o) {
    return true; // the parent class already verifies that the object is the same class
}}
Shikhar Chaudhary
  • 425
  • 1
  • 6
  • 11