Java Class && Method

Class, java.lang:

* public static Class<?>  forName(String className) throws ClassNotFoundException == Class.forName(className, true, currentLoader);

* public T newInstance() throws InstantiationException, IllegalAccessException;

* public boolean isInstance(Object obj)

* public Method[] getMethods() throws SecurityException,受访问权限影响;会反射基类的方法;并且可以从修饰符判断是从哪个基类继承的方法;只反射public方法;

  Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces. Array classes return all the (public) member methods inherited from the Object class. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if this Class object represents a class or interface that has no public member methods, or if this Class object represents a primitive type or void.

* public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException;

* public Method[] getDeclaredMethods() throws SecurityException,由该类声明的方法,不包括基类方法;

  Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private methods, but excludes inherited methods. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no methods, or if this Class object represents a primitive type, an array class, or void. The class initialization method <clinit> is not included in the returned array. If the class declares multiple public member methods with the same parameter types, they are all included in the returned array.

* public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException;

  输出当前类中声明的方法(private, protected, public 以及实现接口的方法),但不包括从父类继承的方法

Method, java.lang.reflect:

* publicObject invoke(Object obj, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException

  Invokes the underlying method represented by this Method object, on the specified object with the specified parameters. Individual parameters are automatically unwrapped to match primitive formal parameters, and both primitive and reference parameters are subject to method invocation conversions as necessary.

  If the underlying method is static, then the specified obj argument is ignored. It may be null.

  If the number of formal parameters required by the underlying method is 0, the supplied args array may be of length 0 or null.

  If the underlying method is an instance method, it is invoked using dynamic method lookup as documented in The Java Language Specification, Second Edition, section 15.12.4.4; in particular, overriding based on the runtime type of the target object will occur.

  If the underlying method is static, the class that declared the method is initialized if it has not already been initialized.

  If the method completes normally, the value it returns is returned to the caller of invoke; if the value has a primitive type, it is first appropriately wrapped in an object. However, if the value has the type of an array of a primitive type, the elements of the array are not wrapped in objects; in other words, an array of primitive type is returned. If the underlying method return type is void, the invocation returns null.

AccessibleObject, Direct Known Subclasses Constructor, Field, Method, java.lang.reflect:

* publicvoid setAccessible(boolean flag) throws SecurityException;

  flag值为true,则阻止进行权限检查;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值