Introspection or introspection of types, allows the program to examine the structure of a type or object at runtime.
For example, at runtime, you can tell if an X type has a specific method / function.
An example in python would be:
class foo(object):
def __init__(self, val):
self.x = val
def bar(self):
return self.x
# dir permite a instrospecção
dir(foo(5))
# resultado
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'bar', 'x']
The dir
function allows you to understand what type foo
contains.
Reflection
Introspection is not the same as Reflection. The reflection allows you to change the type or object data at runtime (the meta data), introspection allows the query and analysis of type information.