Advice接口
/**
*Advice 的标签接口。 实现可以是任何类型的advice,例如拦截 器。
*/
public interface Advice {
}
Interceptor接口
/* 这个接口代表一个通用的拦截器。
* 通用拦截器可以拦截在基础程序中发生的运行时事件。这些时间具体化为Joinpint(连接点)。运行时连接点可以是调用、字段访问、异常等等。
* 这个接口通常不会直接使用。用子接口拦截具体的事件。 例如,下面的类实现了具体的拦截器来实现调试器。
* class DebuggingInterceptor implements MethodInterceptor,
* ConstructorInterceptor {
*
* Object invoke(MethodInvocation i) throws Throwable {
* debug(i.getMethod(), i.getThis(), i.getArgs());
* return i.proceed();
* }
*
* Object construct(ConstructorInvocation i) throws Throwable {
* debug(i.getConstructor(), i.getThis(), i.getArgs());
* return i.proceed();
* }
*
* void debug(AccessibleObject ao, Object this, Object value) {
* ...
* }
* }
public interface Interceptor extends Advice {
}
MethodInterceptor接口
/* 在接口到达目标的途中拦截接口上的调用。它们嵌套在目标的“顶部”。
用户应该实现 invoke(MethodInvacation) 方法,来修改原来的行为。一下的类 实现了一个跟踪拦截器
* class TracingInterceptor implements MethodInterceptor {
* Object invoke(MethodInvocation i) throws Throwable {
* System.out.println("method "+i.getMethod()+" is called on "+
* i.getThis()+" with args "+i.getArguments());
* Object ret=i.proceed();
* System.out.println("method "+i.getMethod()+" returns "+ret);
* return ret;
* }
* }
@FunctionalInterface
public interface MethodInterceptor extends Interceptor {
@Nullable
Object invoke(@Nonnull MethodInvocation invocation) throws Throwable;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。