Explain what is meant by the terms introspection and reflection, with reference to how they are supported by Java.

解决方案 »

  1.   

    Introspection typically goes for such inspection on not being able to map a string class name to a Class object, not being able to resolve a string method name, or specifying a method name that has the wrong type signature for its intended use.
    And reflection is mainly to use reflected fields, methods, and constructors etc.
      

  2.   

    We know that "Introspection" is the ability of a software system to reason about its own changing organization, at a level of self-knowledge conventionally limited to the compiler-time structures. But how is it supported by JAVA?
      

  3.   

        Reflection 是Java被视为动态(或准动态)语言的一个关键性质。这个机制允许程序在运行时透过Reflection APIs取得任何一个已知名称的class的内部信息,包括其modifiers(诸如public, static 等等)、superclass(例如Object)、实现之interfaces(例如Cloneable),也包括fields和methods的所有信息,并可于运行时改变fields内容或唤起methodsReflection。这个字的意思是“反射、映象、倒影”,用在Java身上指的是我们可以于运行时加载、探知、使用编译期间完全未知的classes。换句话说,Java程序可以加载一个运行时才得知名称的class,获悉其完整构造(但不包括methods定义),并生成其对象实体、或对其fields设值、或唤起其methods1。这种“看透class”的能力(the ability of the program to examine itself)被称为introspection(内省、内观、反省)。
      

  4.   

    反射在java的JDK中有支持啊,Reflect包不就是干这个事情的么?之前我们写JSON道JavaBean转换时还用过,开源的方面Apache的Common.util包也可以支持的~