package mao.shu.spring.aop;publicinterfaceCalcUtil<X,Y,R>{public R plus(X x,Y y);public R subtract(X x,Y y);public R multiplication(X x,Y y);public R division(X x,Y y);}
定义一个IntCalc类实现CalcUtil接口
package mao.shu.spring.aop;publicclassIntCalcimplementsCalcUtil<Integer,Integer,Integer>{@Overridepublic Integer plus(Integer x, Integer y)throws Exception {if(x <0|| y <0){thrownewException("请输入正数");}
System.out.println("执行plus()方法 (x = "+x+" y = "+y+")");return x +y;}@Overridepublic Integer subtract(Integer x, Integer y)throws Exception {if(x <0|| y <0){thrownewException("请输入正数");}
System.out.println("执行subtract()方法 (x = "+x+" y = "+y+")");return x - y;}@Overridepublic Integer multiplication(Integer x, Integer y)throws Exception {if(x <0|| y <0){thrownewException("请输入正数");}
System.out.println("执行multiplication()方法 (x = "+x+" y = "+y+")");return x * y;}@Overridepublic Integer division(Integer x, Integer y)throws Exception {if(x <0|| y <0){thrownewException("请输入正数");}
System.out.println("执行division()方法 (x = "+x+" y = "+y+")");return x / y;}}