< prev index next >

src/java.base/share/classes/java/lang/reflect/Method.java

Print this page




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.reflect;
  27 
  28 import sun.reflect.CallerSensitive;
  29 import sun.reflect.MethodAccessor;
  30 import sun.reflect.Reflection;
  31 import sun.reflect.generics.repository.MethodRepository;
  32 import sun.reflect.generics.factory.CoreReflectionFactory;
  33 import sun.reflect.generics.factory.GenericsFactory;
  34 import sun.reflect.generics.scope.MethodScope;
  35 import sun.reflect.annotation.AnnotationType;
  36 import sun.reflect.annotation.AnnotationParser;
  37 import java.lang.annotation.Annotation;
  38 import java.lang.annotation.AnnotationFormatError;
  39 import java.nio.ByteBuffer;

  40 
  41 /**
  42  * A {@code Method} provides information about, and access to, a single method
  43  * on a class or interface.  The reflected method may be a class method
  44  * or an instance method (including an abstract method).
  45  *
  46  * <p>A {@code Method} permits widening conversions to occur when matching the
  47  * actual parameters to invoke with the underlying method's formal
  48  * parameters, but it throws an {@code IllegalArgumentException} if a
  49  * narrowing conversion would occur.
  50  *
  51  * @see Member
  52  * @see java.lang.Class
  53  * @see java.lang.Class#getMethods()
  54  * @see java.lang.Class#getMethod(String, Class[])
  55  * @see java.lang.Class#getDeclaredMethods()
  56  * @see java.lang.Class#getDeclaredMethod(String, Class[])
  57  *
  58  * @author Kenneth Russell
  59  * @author Nakul Saraiya


 158         res.methodAccessor = methodAccessor;
 159         return res;
 160     }
 161 
 162     /**
 163      * Used by Excecutable for annotation sharing.
 164      */
 165     @Override
 166     Executable getRoot() {
 167         return root;
 168     }
 169 
 170     @Override
 171     boolean hasGenericInformation() {
 172         return (getGenericSignature() != null);
 173     }
 174 
 175     @Override
 176     byte[] getAnnotationBytes() {
 177         return annotations;





















 178     }
 179 
 180     /**
 181      * {@inheritDoc}
 182      */
 183     @Override
 184     public Class<?> getDeclaringClass() {
 185         return clazz;
 186     }
 187 
 188     /**
 189      * Returns the name of the method represented by this {@code Method}
 190      * object, as a {@code String}.
 191      */
 192     @Override
 193     public String getName() {
 194         return name;
 195     }
 196 
 197     /**




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.reflect;
  27 
  28 import sun.reflect.CallerSensitive;
  29 import sun.reflect.MethodAccessor;
  30 import sun.reflect.Reflection;
  31 import sun.reflect.generics.repository.MethodRepository;
  32 import sun.reflect.generics.factory.CoreReflectionFactory;
  33 import sun.reflect.generics.factory.GenericsFactory;
  34 import sun.reflect.generics.scope.MethodScope;
  35 import sun.reflect.annotation.AnnotationType;
  36 import sun.reflect.annotation.AnnotationParser;
  37 import java.lang.annotation.Annotation;
  38 import java.lang.annotation.AnnotationFormatError;
  39 import java.nio.ByteBuffer;
  40 import java.util.Arrays;
  41 
  42 /**
  43  * A {@code Method} provides information about, and access to, a single method
  44  * on a class or interface.  The reflected method may be a class method
  45  * or an instance method (including an abstract method).
  46  *
  47  * <p>A {@code Method} permits widening conversions to occur when matching the
  48  * actual parameters to invoke with the underlying method's formal
  49  * parameters, but it throws an {@code IllegalArgumentException} if a
  50  * narrowing conversion would occur.
  51  *
  52  * @see Member
  53  * @see java.lang.Class
  54  * @see java.lang.Class#getMethods()
  55  * @see java.lang.Class#getMethod(String, Class[])
  56  * @see java.lang.Class#getDeclaredMethods()
  57  * @see java.lang.Class#getDeclaredMethod(String, Class[])
  58  *
  59  * @author Kenneth Russell
  60  * @author Nakul Saraiya


 159         res.methodAccessor = methodAccessor;
 160         return res;
 161     }
 162 
 163     /**
 164      * Used by Excecutable for annotation sharing.
 165      */
 166     @Override
 167     Executable getRoot() {
 168         return root;
 169     }
 170 
 171     @Override
 172     boolean hasGenericInformation() {
 173         return (getGenericSignature() != null);
 174     }
 175 
 176     @Override
 177     byte[] getAnnotationBytes() {
 178         return annotations;
 179     }
 180 
 181     /**
 182      * Used by java.lang.MethodTable to optimize comparing/locating
 183      * method signatures.
 184      */
 185     boolean parameterTypesEquals(Method other) {
 186         int len = parameterTypes.length;
 187         if (len != other.parameterTypes.length) {
 188             return false;
 189         }
 190         for (int i = 0; i < len; i++) {
 191             if (parameterTypes[i] != other.parameterTypes[i]) {
 192                 return false;
 193             }
 194         }
 195         return true;
 196     }
 197 
 198     int parameterTypesHashCode() {
 199         return Arrays.hashCode(parameterTypes);
 200     }
 201 
 202     /**
 203      * {@inheritDoc}
 204      */
 205     @Override
 206     public Class<?> getDeclaringClass() {
 207         return clazz;
 208     }
 209 
 210     /**
 211      * Returns the name of the method represented by this {@code Method}
 212      * object, as a {@code String}.
 213      */
 214     @Override
 215     public String getName() {
 216         return name;
 217     }
 218 
 219     /**


< prev index next >