package test.arithmetic; public class Arithmetic1 { /** * @param args */ public static void main(String[] args) { Point<Long> p=new Point<Long>(); p.setX(180l); p.setY(10l); Point<Integer> p2=new Point<Integer>(); p2.setX(120); p2.setY(20); print(p); print(p2); /** x坐标:180 y坐标:10 类型:class java.lang.Long x坐标:120 y坐标:20 类型:class java.lang.Integer */ } public static void print(Point<? extends Number> p){ System.out.println(p); } } class Point<T extends Number>{ private T x; private T y; public T getX() { return x; } public void setX(T x) { this.x = x; } public T getY() { return y; } public void setY(T y) { this.y = y; } @Override public String toString() { return "x坐标:"+x+" y坐标:"+y+" 种类:"+x.getClass(); } }
版权声明:本文博主原创文章,博客,未经同意不得转载。