import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect public class A2 { private static final int MAX = 1000; @Pointcut("call(void C.incI(int)) && args(x)") private void CoupureIncI(int x) { } @Around("CoupureIncI(x)") // AutourDeCoupureIncI renvoie le même type que C.incI. public void AutourDeCoupureIncI(ProceedingJoinPoint joinPoint, int x) throws Throwable { if (((C) joinPoint.getTarget()).i + x > MAX) throw new RuntimeException(); // En cas de méthode static, pas besoin de joinPoint.getTarget(). joinPoint.proceed(new Object[] { x, joinPoint.getTarget() }); } }