泛型之元组示例

package test;
import demon.Person;
class Tuple<A, B> {
public final A first;
public final B second;

public Tuple(A a, B b) {
first = a;
second = b;
}

public String toString() {
return "(" + first + "," + second + ")";

}

public A getFirst() {
return first;
}

public B getSecond() {
return second;
}
}
public class Test006 {
public static void main(String[] args) {
Tuple<Person, Integer> t = new Tuple<>(new Person("zhangsan"), 12);
System.out.println(t.getFirst().getName());
System.out.println(t.getSecond());
}
}
posted @ 2019-07-25 21:44  玄空2  阅读(225)  评论(0编辑  收藏  举报