I want to implement my own Pair template class which will be used as the key in a HashMap or possibly other collections. What I have done so far is this:
import java.util.Objects;
public class Pair<T1, T2> {
public T1 first;
public T2 second;
public Pair(T1 first, T2 second) {
this.first = first;
this.second = second;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Pair)) {
return false;
}
Pair<T1, T2> other = (Pair<T1, T2>) obj;
return this.first.equals(other.first) && this.second.equals(other.second);
}
@Override
public int hashCode() {
return Objects.hash(first, second);
}
}
IntelliJ throws a warning that says:
Unchecked cast: 'java.lang.Object' to 'gr.uoa.di.madgik.kbt.utils.Pair<T1,T2>'
Is there something I can do about it?
Are there are any other problems with my implementation?
Pairclass, when there are already plenty of implementations? \$\endgroup\$