AnnotationInvocationHandler.java 文件源码

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

项目:jvm-stm 作者:
public Object invoke(Object proxy, Method method, Object[] args)
   throws Throwable
 {
   String methodName = method.getName().intern();

   if (args == null || args.length == 0)
     {
if (methodName == "toString")
  {
    return toString();
  }
else if (methodName == "hashCode")
  {
    return Integer.valueOf(hashCode());
  }
else if (methodName == "annotationType")
  {
    return type;
  }
else
  {
    Object val = memberValues.get(methodName);
    if (val == null)
      {
    throw new IncompleteAnnotationException(type, methodName);
      }
    try
      {
    if (val.getClass().isArray())
      val = coerce((Object[])val, method.getReturnType());
      }
    catch (ArrayStoreException _)
      {
    throw new AnnotationTypeMismatchException
      (method, val.getClass().getName());
      }
    if (! getBoxedReturnType(method).isInstance(val))
      throw (new AnnotationTypeMismatchException
         (method, val.getClass().getName()));
    return val;
  }
     }
   else if (args.length == 1)
     {
if (methodName == "equals")
  {
    return Boolean.valueOf(equals(proxy, args[0]));
  }
     }
   throw new InternalError("Invalid annotation proxy");
 }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号