Method类及相关类解读

Method类及相关类解读

一、简介

接前面Field类解读,这里介绍Method类及相关类。

二、Method结构

2.1 Method解释

method的方法提供了对于在类或接口中单个方法的信息和访问,反射方法可能是一个类方法或实体方法(包含抽象方法)。

2.2 Method定义
public final class Method extends Executable {
   }

关联的Executable定义(这里仅列出独有方法)如下:

public abstract class Executable extends AccessibleObject
    implements Member, GenericDeclaration {
   
/***其他方法省略,在其他博客中已介绍,使用类似 *****/

//返回方法的参数数组
public Parameter[] getParameters() {
   }

//返回方法的参数声明AnnotatedType数组
public AnnotatedType[] getAnnotatedParameterTypes() {
   }

//返回方法的参数声明异常数组
public AnnotatedType[] getAnnotatedExceptionTypes() {
   }
}

使用示例接下来介绍。

三、Method方法

Method的源码解读如下:

package java.lang.reflect;

import sun.reflect.CallerSensitive;
import sun.reflect.MethodAccessor;
import sun.reflect.Reflection;
import sun.reflect.generics.repository.MethodRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.scope.MethodScope;
import sun.reflect.annotation.AnnotationType;
import sun.reflect.annotation.AnnotationParser;
import java.lang.annotation.Annotation;
import java.lang.annotation.AnnotationFormatError;
import java.nio.ByteBuffer;

//method的方法提供了对于在类或接口中单个方法的信息和访问,反射方法可能是一个类方法或实体方法(包含抽象方法)
public final class Method extends Executable {
   
    //返回声明方法的类实例,
    public Class<?> getDeclaringClass() {
   }

    //返回方法的名称
    public String getName() {
   }

    //返回方法修饰符的int表示
    public int getModifiers() {
   }

    //返回方法按声明顺序的类型变量数组
    public TypeVariable<Method>[] getTypeParameters() {
   }

    //返回方法返回类型
    public Class<?> getReturnType() {
   }

    //返回方法返回的Type类型,这里为T
    public Type getGenericReturnType() {
   }

    //返回方法按声明顺序的参数Class数组,没有则返回长度为0的数组
    public Class<?>[] getParameterTypes() {
   }

    //返回方法的参数个数
    public int getParameterCount</
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值