Created
November 17, 2025 16:18
-
-
Save AL3X-69/4747301d5b9a9821f585856cce40756b to your computer and use it in GitHub Desktop.
Simple Java Pair object implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dev.alex6.tsle.utils; | |
| import java.util.Objects; | |
| public class Pair<A, B> { | |
| private A a; | |
| private B b; | |
| public Pair() {} | |
| public Pair(A a, B b) { | |
| this.a = a; | |
| this.b = b; | |
| } | |
| public A getA() { | |
| return a; | |
| } | |
| public void setA(A a) { | |
| this.a = a; | |
| } | |
| public B getB() { | |
| return b; | |
| } | |
| public void setB(B b) { | |
| this.b = b; | |
| } | |
| @Override | |
| public boolean equals(Object o) { | |
| if (o == null || getClass() != o.getClass()) return false; | |
| Pair<?, ?> pair = (Pair<?, ?>) o; | |
| return Objects.equals(a, pair.a) && Objects.equals(b, pair.b); | |
| } | |
| @Override | |
| public int hashCode() { | |
| return Objects.hash(a, b); | |
| } | |
| @Override | |
| public String toString() { | |
| return String.format("(%s, %s)", a, b); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment