Class,Method

  • public final class Class<T>
    extends Object
    implements Serializable, GenericDeclaration, Type, AnnotatedElement
    Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation注释 is a kind of interface. Every array also belongs属于  to a class that is reflected被映射 as a  Class object that is shared by all arrays with the same element元素 type and number of dimensions维数. The primitive基本 Java types ( boolean, byte, char, short, int, long, float, and double), and the keyword关键字  void are also represented as Class objects.

    Class has no public constructor构造方法. Instead加载 Class objects are constructed automatically自动 by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader加载.

    The following example uses a Class object to print the class name of an object:

         void printClassName(Object obj) {
             System.out.println("The class of " + obj +
                                " is " + obj.getClass().getName());
         }
     

    It is also possible to get the Class object for a named指定 type (or for void) using a class literal类字面值. See Section 15.8.2 ofThe Java™ Language Specification. For example:

    System.out.println("The name of class Foo is: "+Foo.class.getName());
    Since:
    JDK1.0
    See Also:

    ClassLoader.defineClass(byte[], int, int), Serialized Form    



    • public final class Method
      extends AccessibleObject
      implements GenericDeclaration, Member
      A Method provides information about, and access to, a single method on a class or interface. The reflected反映 method may be a class method or an instance method (including an abstract method).

      A Method permits允许  widening扩展  conversions to occur when matching the actual parameters实参  to invoke调用  with the underlying method's formal parameters, but it throws anIllegalArgumentException if a narrowing缩小  conversion would occur.

      See Also:
      Member, Class, Class.getMethods(), Class.getMethod(String, Class[]), Class.getDeclaredMethods(), Class.getDeclaredMethod(String, Class[])

你可能感兴趣的:(Class,Method)