Sometimes during the design of an interface I want to return two objects instead of one for a certain method. Yes, this might be bad practice. But sometimes I just need it. In good old c++ with stl, there was a solution for this by using pairs. In java, there's no such thing as pairs and a Map is too bulky. So here's the Java 5 Pair implementation:
public final class Pair {
public final A first;
public final B second;
public Pair(A first, B second) {
this.first = first;
this.second = second;
}
public A getFirst() {
return first;
}
public B getSecond() {
return second;
}
}
Geen opmerkingen:
Een reactie posten