pair是一个方便的java工具类。
假设你的私有方法返回值刚好是两个,使用pair就很合适。当然如果超过三个,那就需要另写包装类了。
这里直接贴代码了,使用时只需要定义一下泛型即可。
public class Pair<T, V> implements Serializable {
private T name;
private V value;
public Pair(T name, V value) {
this.name = name;
this.value = value;
}
public T getName() {
return this.name;
}
public void setName(T name) {
this.name = name;
}
public V getValue() {
return this.value;
}
public void setValue(V value) {
this.value = value;
}
}