package _5_29;
public class GeneMethodDemo {
public static void main(String[] args) {
NewPoint<Integer, Integer> p1 = new NewPoint<Integer, Integer>();
p1.setX(10);
p1.setY(20);
p1.printPoint(p1.getX(), p1.getY()); // Calling the generic method printPoint()
NewPoint<Double, String> p2 = new NewPoint<Double, String>();
p2.setX(25.4);
p2.setY("东经 180 度");
p2.printPoint(p2.getX(), p2.getY()); // Calling the generic method printPoint()
}
}
package _5_29;
class NewPoint<T1, T2> {
T1 x;
T2 y;
public T1 getX() {
return x;
}
public void setX(T1 x) {
this.x = x;
}
public T2 getY() {
return y;
}
public void setY(T2 y) {
this.y = y;
}
// Define a method to print the point
public <S1, S2> void printPoint(S1 x, S2 y) {
S1 m = x;
S2 n = y;
System.out.println("This point is: " + m + ", " + n);
}
}
2万+

被折叠的 条评论
为什么被折叠?



