d.TrueMethodMatcher:
TrueMethodMatcher作为默认切入点的默认方法匹配器,主要告诉切入点对哪些方法进行增强,源码如下:
- class TrueMethodMatcher implements MethodMatcher, Serializable { //单态模式
- public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher(); //单态模式构造方法
- private TrueMethodMatcher() { }
- //不支持运行时调用 public boolean isRuntime() {
- return false; }
- //切入点匹配方法时调用,默认匹配所有的方法 public boolean matches(Method method, Class targetClass) {
- return true; }
- //运行时调用将抛出异常 public boolean matches(Method method, Class targetClass, Object[] args) {
- throw new UnsupportedOperationException(); }
- //获取单态模式对象的方法 private Object readResolve() {
- return INSTANCE; }
- public String toString() { return "MethodMatcher.TRUE";
- } }
从上面方法匹配器的源码,我们可以看出,切入点对方法进行匹配时不支持运行时的匹配,如果在运行时进行匹配将抛出异常。