package collection
public class Location<E>{
private E x;
private E y;
public Point(E x, E y) {
super();
this.x = x;
this.y = y;
}
public E getX() {
11 return x;
12 }
13
14 public void setX(E x) {
15 this.x = x;
16 }
17
18 public E getY() {
19 return y;
20 }
21
22 public void setY(E y) {
23 this.y = y;
24 }
public String toString(){
return "("+x+","+y+")";
}
}
package collection
public class TypeDemo{
public static void main(String[] args){
Location<Integer> loc1 = new Location<Integer>(1,2);
loc1.setX(2.2);
double x1 = loc1.getX();
System.out.println("loc1:"+loc1);
System.out.println("x1:"+loc1);
Location<Double> loc1 = new Location<Double>(1,2);
loc1.setX(2.2);
int x1 = loc1.getX();
System.out.println("loc1:"+loc1);
System.out.println("x1:"+loc1);
}
}