What is the difference between introspection and reflection?

前端 未结 3 942
耶瑟儿~
耶瑟儿~ 2021-01-30 03:58

Can anyone explain from a language/environment agnostic perspective the difference between these two notions?

Also is there a set of conditions that programming language

3条回答
  •  一整个雨季
    2021-01-30 04:42

    Type introspection:

    Ability of a programming language to examine the type or properties of an object at runtime.

    Example (Java):

    String myObj1 = new String();
    MyCustomObject myObj2 = new MyCustomObject();
    if(myObj2 instanceof MyCustomObject) {
        System.out.println("This is an example of type interospection");
    }
    


    Reflection:

    Ability of a programming language to achieve below things at runtime.

    • Type introspect (as seen above)
    • Examine and modify a object.
    • and much more

提交回复
热议问题