I just made a Java n-tuple which is type-safe.
I\'m using some unconventional methods to achieve type-safety (I just made it for fun).
Can someone can give some
saw this code in wave project
public class Tuple {
private final A[] elements;
public static Tuple of(A ... elements) {
return new Tuple(elements);
}
public Tuple(A ... elements) {
this.elements = elements;
}
public A get(int index) {
return elements[index];
}
public int size() {
return elements.length;
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || o.getClass() != this.getClass()) {
return false;
}
Tuple o2 = (Tuple) o;
return Arrays.equals(elements, o2.elements);
}
@Override
public int hashCode() {
return Arrays.hashCode(elements);
}
@Override
public String toString() {
return Arrays.toString(elements);
}
}