As far as i know and understand,
Reflection is the ability to create/modify source code at run time.
From Wikipedia:
Dynamic languages are languages that we can eval (evaluate direct from string) at run-time.
From wikipedia: "extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system"
Ok, now, my question is: How static languageד (without eval ability) can have reflection (e.g Java)? (the new source code doesn't evaluate? :/)
Thanks in advance!
I think wikipedia explanation is not really phrased well.
Reflection (or introspection) is not about creation of code during runtime but rather about ability of code to reflect on itself in runtime (and modify it's behavior based on this). Examples would be getting info about type of the object (like RTTI in C++) or getting metadata associated with object (like annotations in Java).
Runtime code generation is more related to first-classness than to reflection, so I would argue that current wikipedia article is kind of misleading.
UPDATE
In other words answer to this:
Ok, now, my question is, how can static language (without eval ability) can have reflection (e.g Java)?
... would be that reflection does not rely on evel ability. These are 2 separate language features.
And also, as Giulio Franco pointed out in the comments - Java is capable of runtime code generation\manipulation (see CGLIB for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With