在一次方法调用就能返回多个对象,实现return 的这个功能,采用泛型实现Tuple
public class Tuple<A, B> { public final A first; public final B second; public Tuple(A first, B second) { this.first = first; this.second = second; } @Override public String toString() { return "Tuple{" + "first=" + first + ", second=" + second + '}'; } public static void main(String[] args) { Tuple<String, Integer> tuple = new Tuple<>("zhang", 12); System.out.println(tuple.first); System.out.println(tuple.second); } } class ThreeTuple<A, B, C> extends Tuple<A, B> { public final C third; public ThreeTuple(A first, B second, C third) { super(first, second); this.third = third; } } class FourTuple<A, B, C, D> extends ThreeTuple<A, B, C> { public final D fourth; public FourTuple(A first, B second, C third, D fourth) { super(first, second, third); this.fourth = fourth; } }