0620.反射(Reflection)

內容

    沒有標題

    Reflection

    概念可以參考 Java Reflection
    僅在實作上的語法稍加不同


    scala> val s = classOf[String]
    s: java.lang.Class[String] = class java.lang.String

    scala> s.

    asInstanceOf              asSubclass                cast                      desiredAssertionStatus    getAnnotation
    getAnnotations            getCanonicalName          getClassLoader            getClasses                getComponentType
    getConstructor            getConstructors           getDeclaredAnnotations    getDeclaredClasses        getDeclaredConstructor
    getDeclaredConstructors   getDeclaredField          getDeclaredFields         getDeclaredMethod         getDeclaredMethods
    getDeclaringClass         getEnclosingClass         getEnclosingConstructor   getEnclosingMethod        getEnumConstants
    getField                  getFields                 getGenericInterfaces      getGenericSuperclass      getInterfaces
    getMethod                 getMethods                getModifiers              getName                   getPackage
    getProtectionDomain       getResource               getResourceAsStream       getSigners                getSimpleName
    getSuperclass             getTypeParameters         isAnnotation              isAnnotationPresent       isAnonymousClass
    isArray                   isAssignableFrom          isEnum                    isInstance                isInstanceOf
    isInterface               isLocalClass              isMemberClass             isPrimitive               isSynthetic
    newInstance               toString




    scala> val wf3 = classOf[WisdomFish02]
    wf3: java.lang.Class[WisdomFish02] = class WisdomFish02

    scala> wf3.

    asInstanceOf              asSubclass                cast                      desiredAssertionStatus    getAnnotation
    getAnnotations            getCanonicalName          getClassLoader            getClasses                getComponentType
    getConstructor            getConstructors           getDeclaredAnnotations    getDeclaredClasses        getDeclaredConstructor
    getDeclaredConstructors   getDeclaredField          getDeclaredFields         getDeclaredMethod         getDeclaredMethods
    getDeclaringClass         getEnclosingClass         getEnclosingConstructor   getEnclosingMethod        getEnumConstants
    getField                  getFields                 getGenericInterfaces      getGenericSuperclass      getInterfaces
    getMethod                 getMethods                getModifiers              getName                   getPackage
    getProtectionDomain       getResource               getResourceAsStream       getSigners                getSimpleName
    getSuperclass             getTypeParameters         isAnnotation              isAnnotationPresent       isAnonymousClass
    isArray                   isAssignableFrom          isEnum                    isInstance                isInstanceOf
    isInterface               isLocalClass              isMemberClass             isPrimitive               isSynthetic
    newInstance               toString



    Comments