AnnotationInvocationHandler.java 文件源码

java
阅读 39 收藏 0 点赞 0 评论 0

项目:Alchemy 作者:
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String name = method.getName();
    Class<?>[] types = method.getParameterTypes();
    InvocationHandler proxyMethod = memberProxys.get(name);
    if (proxyMethod != null)
        return proxyMethod.invoke(proxy, method, args);
    if (name.equals("equals") && types.length == 1 && types[0] == Object.class)
        return equalsImpl(args[0]);
    if (types.length != 0)
        throw new AssertionError("Too many parameters for an annotation method");
    switch (name) {
        case "toString":
            return toStringImpl();
        case "hashCode":
            return hashCodeImpl();
        case "annotationType":
            return type;
    }
    Object result = memberValues.get(name);
    if (result == null)
        throw new IncompleteAnnotationException(type, name);
    return result.getClass().isArray() ? Tool.cloneArray(result) : result;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号