Class Method

java.lang

Class Class<T>

  • Type Parameters:
    T - the type of the class modeled by thisClass object. For example, the type ofString.class isClass<String>. Use Class<?> if the class being modeled is unknown.
    All Implemented Interfaces:
    Serializable,AnnotatedElement,GenericDeclaration,Type


    public final class Class<T>
    extends Object
    implements Serializable, GenericDeclaration, Type, AnnotatedElement
    Instances of the class Classrepresent(表示) classes and interfaces in a running Java application. An enum is akind(种类) of class and an annotation(注释) is a kind of interface. Every array alsobelongs(属于) to a class that isreflected(反射) as aClass object that isshared(共享) by all arrays with the same element type and number ofdimensions(大小). Theprimitive(基本) Java types (boolean,byte,char,short, int, long, float, and double), and the keyword(关键字)void are also represented asClass objects.

    Class has no public cons tructor(构造方法). InsteadClass objects are constructedautomatically(自动的) by the JavaVirtual Machine(虚拟机) as classes are loaded and by calls to thedefineClass 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 theClass object for anamed(指定的) type (or for void) using a class literal(字面的). See Section 15.8.2 ofThe Java™ LanguageSpecification(规范). For example:

    System.out.println("The name of class Foo is: "+Foo.class.getName());

    java.lang.reflect

    Class Method

    • All Implemented Interfaces:
      AnnotatedElement, GenericDeclaration, Member


      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 tooccur(发生) whenmatching(匹配) the actual(实际的) parameters to invoke with theunderlying(基础) method'sformal(形式的) parameters, but it throws anIllegalArgumentException if anarrowing(收缩) conversion would occur.


你可能感兴趣的:(method)