public class Triple<L, K, V> {
private final L first;
private final K second;
private final V third;
public Triple(L first, K second, V third) {
this.first = first;
this.second = second;
this.third = third;
}
public L getFirst() {
return this.first;
}
public K getSecond() {
return this.second;
}
public V getThird() {
return this.third;
}
}
可以这样实现:
Triple<String, Integer, Integer> myTriple = new Triple<>("Hello world", 42, 666);
但是这里的真正概念是将数据点表示为代码中的 。如果您有一组数据(“我有一个字符串和两个表示 某些 含义的整数”),那么您希望将其封装在一个类下。