<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.aletopedia.org/index.php?action=history&amp;feed=atom&amp;title=Reflective_programming</id>
	<title>Reflective programming - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.aletopedia.org/index.php?action=history&amp;feed=atom&amp;title=Reflective_programming"/>
	<link rel="alternate" type="text/html" href="https://www.aletopedia.org/index.php?title=Reflective_programming&amp;action=history"/>
	<updated>2026-12-06T20:41:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://www.aletopedia.org/index.php?title=Reflective_programming&amp;diff=202399&amp;oldid=prev</id>
		<title>~2026-57829-28: /* Java */</title>
		<link rel="alternate" type="text/html" href="https://www.aletopedia.org/index.php?title=Reflective_programming&amp;diff=202399&amp;oldid=prev"/>
		<updated>2026-11-01T19:28:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Java&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Ability of a process to examine and modify itself}}&lt;br /&gt;
{{Distinguish|Reflection (computer graphics)|Recursion (computer science)}}&lt;br /&gt;
&lt;br /&gt;
In [[computer science]], &amp;#039;&amp;#039;&amp;#039;reflective programming&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;reflection&amp;#039;&amp;#039;&amp;#039; is the ability of a [[Process (computing)|process]] to examine, [[Introspection (computer science)|introspect]], and modify its own structure and behavior.&amp;lt;ref&amp;gt;{{Citation |title=A Tutorial on Behavioral Reflection and its Implementation by Jacques Malenfant et al. |publisher=unknown |url=http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/malenfant.pdf |archive-url=https://web.archive.org/web/20170821214626/http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/malenfant.pdf |archive-date=21 August 2017 |access-date=23 June 2019}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Historical background==&lt;br /&gt;
The earliest computers were programmed in their native [[assembly language]]s, which were inherently reflective, as these original architectures could be programmed by defining instructions as data and using [[self-modifying code]]. As the bulk of programming moved to higher-level [[compiled languages]] such as [[ALGOL]], [[COBOL]], [[Fortran]], [[Pascal (programming language)|Pascal]], and [[C (programming language)|C]], this reflective ability largely disappeared until new programming languages with reflection built into their type systems appeared.{{Citation needed|date=July 2015}}&lt;br /&gt;
&lt;br /&gt;
[[Brian Cantwell Smith]]&amp;#039;s 1982 doctoral dissertation introduced the notion of computational reflection in [[Procedural programming|procedural]] [[programming languages]] and the notion of the [[meta-circular interpreter]] as a component of 3-[[Lisp (programming language)|Lisp]].&amp;lt;ref&amp;gt;Brian Cantwell Smith, [http://hdl.handle.net/1721.1/15961 Procedural Reflection in Programming Languages], Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD dissertation, 1982.&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;Brian C. Smith. [http://publications.csail.mit.edu/lcs/specpub.php?id=840 Reflection and semantics in a procedural language] {{Webarchive|url=https://web.archive.org/web/20151213034343/http://publications.csail.mit.edu/lcs/specpub.php?id=840 |date=2015-12-13 }}. Technical Report MIT-LCS-TR-272, Massachusetts Institute of Technology, Cambridge, Massachusetts, January 1982.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Uses==&lt;br /&gt;
Reflection helps programmers make generic software libraries to display data, process different formats of data, perform [[serialization]] and deserialization of data for communication, or do bundling and unbundling of data for containers or bursts of communication. Reflective systems may provide a [[Mirror (programming)|mirror]] type, used as a decoupled reflection of an object or identifier.&lt;br /&gt;
&lt;br /&gt;
Effective use of reflection almost always requires a plan: A design framework, encoding description, object library, a map of a database or entity relations.&lt;br /&gt;
&lt;br /&gt;
Reflection makes a language more suited to network-oriented code. For example, it assists languages such as [[Java (programming language)|Java]] to operate well in networks by enabling libraries for serialization, bundling and varying data formats. Languages without reflection such as [[C (programming language)|C]] are required to use auxiliary compilers for tasks like Abstract Syntax Notation ([[ASN.1]]) to produce code for serialization and bundling.&lt;br /&gt;
&lt;br /&gt;
Reflection can be used for observing and modifying program execution at [[Execution (computing)|runtime]]. A reflection-oriented program component can monitor the execution of an enclosure of code and can modify itself according to a desired goal of that enclosure. This is typically accomplished by dynamically assigning program code at runtime.&lt;br /&gt;
&lt;br /&gt;
In [[object-oriented programming]] languages such as [[Java (programming language)|Java]], reflection allows &amp;#039;&amp;#039;inspection&amp;#039;&amp;#039; of [[Class (programming)|classes]], [[Interface (computing)|interfaces]], [[Field (computer science)|fields]], and [[Method (computer programming)|methods]] at runtime without knowing the names of the interfaces, fields, methods at [[compile time]]. It also allows &amp;#039;&amp;#039;[[Instantiation (computing)|instantiation]]&amp;#039;&amp;#039; of new objects and &amp;#039;&amp;#039;invocation&amp;#039;&amp;#039; of methods.&lt;br /&gt;
&lt;br /&gt;
Reflection is often used as part of [[software testing]], such as for the runtime creation/instantiation of [[mock object]]s.&lt;br /&gt;
&lt;br /&gt;
Reflection is also a key strategy for [[metaprogramming]].&lt;br /&gt;
&lt;br /&gt;
In some object-oriented programming languages such as [[C Sharp (programming language)|C#]] and [[Java (programming language)|Java]], reflection can be used to bypass [[member accessibility]] rules. For C#-properties this can be achieved by writing directly onto the (usually invisible) backing field of a non-public property. It is also possible to find non-public methods of classes and types and manually invoke them. This works for project-internal files as well as external libraries such as [[.NET Framework|.NET]]&amp;#039;s assemblies and Java&amp;#039;s archives.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
{{Unreferenced section|date=January 2008}}&lt;br /&gt;
A language that supports reflection provides a number of features available at runtime that would otherwise be difficult to accomplish in a lower-level language. Some of these features are the abilities to:&lt;br /&gt;
* Discover and modify [[source code]] constructions (such as code blocks, [[Class (programming)|classes]], methods, protocols, etc.) as [[first-class object]]s at [[Execution (computing)|runtime]]. Readable object metadata is provided as a [[Mirror (programming)|mirror]].&lt;br /&gt;
* Convert a [[String (computer science)|string]] matching the symbolic name of a class or function into a reference to or invocation of that class or function.&amp;lt;ref&amp;gt;{{Cite web |title=CLHS: Function INTERN |url=http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_intern.html |access-date=2026-03-27 |website=www.ai.mit.edu}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Evaluate a string as if it were a source-code statement at runtime.&amp;lt;ref&amp;gt;{{Cite web |title=Built-in Functions |url=https://docs.python.org/3/library/functions.html |access-date=2026-03-27 |website=Python documentation |language=en}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |date=2026-01-21 |title=eval() - JavaScript {{!}} MDN |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval |access-date=2026-03-27 |website=MDN Web Docs |language=en-US}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Create a new [[Interpreter (computing)|interpreter]] for the language&amp;#039;s [[bytecode]] to give a new meaning or purpose for a programming construct.&lt;br /&gt;
&lt;br /&gt;
These features can be implemented in different ways. In [[MOO (programming language)|MOO]], reflection forms a natural part of everyday programming idiom. When verbs (methods) are called, various variables such as &amp;lt;code&amp;gt;verb&amp;lt;/code&amp;gt; (the name of the verb being called) and &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; (the object on which the verb is called) are populated to give the context of the call. Security is typically managed by accessing the caller stack programmatically: Since &amp;lt;code&amp;gt;callers()&amp;lt;/code&amp;gt; is a list of the methods by which the current verb was eventually called, performing tests on &amp;lt;code&amp;gt;callers()[0]&amp;lt;/code&amp;gt; (the command invoked by the original user) allows the verb to protect itself against unauthorised use.&amp;lt;ref&amp;gt;{{cite book |last1=Herzeel |first1=Charlotte |title=Self-Sustaining Systems |last2=Costanza |first2=Pascal |last3=D&amp;#039;Hondt |first3=Theo |publisher=Springer |year=2008 |series=Lecture Notes in Computer Science |volume=5146 |pages=87–122 |chapter=Reflection for the masses |doi=10.1007/978-3-540-89275-5_5}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compiled languages rely on their runtime system to provide information about the source code. A compiled [[Objective-C]] executable, for example, records the names of all methods in a block of the executable, providing a table to correspond these with the underlying methods (or selectors for these methods) compiled into the program. In a compiled language that supports runtime creation of functions, such as [[Common Lisp]], the runtime environment must include a compiler or an interpreter.&amp;lt;ref&amp;gt;{{cite book |last1=Herzeel |first1=Charlotte |title=Self-Sustaining Systems |last2=Costanza |first2=Pascal |last3=D&amp;#039;Hondt |first3=Theo |publisher=Springer |year=2008 |series=Lecture Notes in Computer Science |volume=5146 |pages=87–122 |chapter=Reflection for the masses |doi=10.1007/978-3-540-89275-5_5}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reflection can be implemented for languages without built-in reflection by using a [[program transformation]] system to define automated source-code changes.&lt;br /&gt;
&lt;br /&gt;
==Security considerations==&lt;br /&gt;
&lt;br /&gt;
Reflection may allow a user to create unexpected [[control flow]] paths through an application, potentially bypassing security measures. This may be exploited by attackers.&amp;lt;ref&amp;gt;{{cite report |first1=Paulo |last1=Barros |first2=René |last2=Just |first3=Suzanne |last3=Millstein |first4=Paul |last4=Vines |first5=Werner |last5=Dietl |first6=Marcelo |last6=d&amp;#039;Amorim |first7=Michael D. |last7=Ernst |date=August 2015 |title=Static Analysis of Implicit Control Flow: Resolving Java Reflection and Android Intents |url=https://homes.cs.washington.edu/~mernst/pubs/implicit-control-flow-tr150801.pdf |publisher=University of Washington |id=UW-CSE-15-08-01 |access-date=October 7, 2021 }}&amp;lt;/ref&amp;gt; Historical [[Vulnerability (computing)|vulnerabilities]] in Java caused by unsafe reflection allowed code retrieved from potentially untrusted remote machines to break out of the Java [[Sandbox (computer security)|sandbox]] security mechanism. A large scale study of 120 Java vulnerabilities in 2013 concluded that unsafe reflection is the most common vulnerability in Java, though not the most exploited.&amp;lt;ref&amp;gt;{{cite magazine |author=Eauvidoum, Ieu |author2=disk noise |date=October 5, 2021 |title=Twenty years of Escaping the Java Sandbox |url=http://phrack.org/issues/70/7.html#article |magazine=[[Phrack]] |volume=10 |issue=46 |access-date=October 7, 2021}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Runtime performance==&lt;br /&gt;
Runtime reflection systems introduce a non-negligible [[runtime performance]] overhead. For instance, in [[Java (programming language)|Java]], because reflective operations are resolved dynamically at execution time, many [[Java compiler|compiler]] and [[JVM]] optimizations—such as [[method inlining]], [[static binding]], and aggressive just-in-time specialization—cannot be fully applied. As a consequence, reflective calls are typically slower than their statically resolved counterparts. [[Microbenchmark]] and application-level studies on Java have shown that reflective operations can incur substantial runtime overhead, especially for [[method invocation]] and dynamic object creation, with slowdowns ranging from around 20–40% in moderate cases to more than 300× in heavily reflective dispatch scenarios.&amp;lt;ref name=&amp;quot;Garcia2026&amp;quot;&amp;gt;Miguel Garcia, Francisco Ortin. [https://doi.org/10.1145/3815583 Characterizing the Usage and Performance Impact of Java Reflection: An Empirical Study], ACM Transactions on Software Engineering and Methodology, 2026.&amp;lt;/ref&amp;gt; In sequential applications, reflection can significantly increase [[execution time]] and memory consumption when used in performance-critical code paths. In [[Thread (computing)|multithreaded applications]], reflective implementations generally preserve [[scalability]], but still exhibit noticeably higher absolute execution times—commonly between 1.5x and 10× slower—than equivalent non-reflective code.&amp;lt;ref name=&amp;quot;Garcia2026&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In languages like [[C++]] and [[Rust (programming language)|Rust]], reflection is performed at [[compile time]]. Compile-time reflection systems are weaker than runtime reflection systems like those of Java and C#, but incur no runtime overhead due to being performed during compilation.&amp;lt;ref&amp;gt;{{Cite web|title=C++26 Reflection: What It Actually Changes for Large Codebases|url=https://www.wholetomato.com/blog/cpp26-reflection-large-codebases/|publisher=Whole Tomato|author=Tristan Soliven|date=1 May 2026|website=wholetomato.com}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
The following code snippets create an [[instance (computer science)|instance]] {{code|foo}} of [[Class (programming)|class]] {{code|Foo}} and invoke its [[method (computer science)|method]] {{code|PrintHello}}. For each [[programming language]], normal and reflection-based call sequences are shown.&lt;br /&gt;
&lt;br /&gt;
=== Common Lisp ===&lt;br /&gt;
The example below is in [[Common Lisp]] using the [[Common Lisp Object System]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(defclass foo () ())&lt;br /&gt;
(defmethod print-hello ((f foo)) (format T &amp;quot;Hello from ~S~%&amp;quot; f))&lt;br /&gt;
&lt;br /&gt;
;; Normal, without reflection&lt;br /&gt;
(let ((foo (make-instance &amp;#039;foo)))&lt;br /&gt;
  (print-hello foo))&lt;br /&gt;
&lt;br /&gt;
;; With reflection to look up the class named &amp;quot;foo&amp;quot; and the method&lt;br /&gt;
;; named &amp;quot;print-hello&amp;quot; that specializes on &amp;quot;foo&amp;quot;.&lt;br /&gt;
(let* ((foo-class (find-class (read-from-string &amp;quot;foo&amp;quot;)))&lt;br /&gt;
       (print-hello-method (find-method (symbol-function (read-from-string &amp;quot;print-hello&amp;quot;))&lt;br /&gt;
                                        nil (list foo-class))))&lt;br /&gt;
  (funcall (sb-mop:method-generic-function print-hello-method)&lt;br /&gt;
           (make-instance foo-class)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C ===&lt;br /&gt;
Reflection is not possible in [[C (programming language)|C]], though parts of reflection can be emulated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef struct {&lt;br /&gt;
    // ...&lt;br /&gt;
} Foo;&lt;br /&gt;
&lt;br /&gt;
typedef void (*Method)(void*);&lt;br /&gt;
&lt;br /&gt;
// The method: Foo::printHello&lt;br /&gt;
void Foo_printHello(void* _) {&lt;br /&gt;
    printf(&amp;quot;Hello, world!\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Simulated method table&lt;br /&gt;
typedef struct {&lt;br /&gt;
    const char* name;&lt;br /&gt;
    Method fn;&lt;br /&gt;
} MethodEntry;&lt;br /&gt;
&lt;br /&gt;
const MethodEntry FOO_METHODS[] = {&lt;br /&gt;
    { &amp;quot;printHello&amp;quot;, Foo_printHello },&lt;br /&gt;
    { NULL, NULL } // Sentinel to mark end&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// Simulate reflective method lookup&lt;br /&gt;
Method findMethodByName(const char* name) {&lt;br /&gt;
    for (size_t i = 0; FOO_METHODS[i].name; i++) {&lt;br /&gt;
        if (strcmp(FOO_METHODS[i].name, name) == 0) {&lt;br /&gt;
            return FOO_METHODS[i].fn;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return NULL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    // Without reflection&lt;br /&gt;
    Foo foo;&lt;br /&gt;
    Foo_printHello(&amp;amp;foo);&lt;br /&gt;
&lt;br /&gt;
    // With emulated reflection&lt;br /&gt;
    Foo* reflected = (Foo*)malloc(sizeof(Foo));&lt;br /&gt;
    if (!reflected) {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Memory allocation failed\n&amp;quot;);&lt;br /&gt;
        return EXIT_FAILURE;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    const char* name = &amp;quot;printHello&amp;quot;;&lt;br /&gt;
    Method m = findMethodByName(name);&lt;br /&gt;
&lt;br /&gt;
    if (m) {&lt;br /&gt;
        m(reflected);&lt;br /&gt;
    } else {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Method &amp;#039;%s&amp;#039; not found\n&amp;quot;, name);&lt;br /&gt;
        free(reflected);&lt;br /&gt;
        return EXIT_FAILURE;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    free(reflected);&lt;br /&gt;
    return EXIT_SUCCESS;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
The example below is in [[C++]] (using [[Reflection (C++)|reflection]] added in [[C++26]]).&amp;lt;ref&amp;gt;{{Cite web|title=Standard library header &amp;lt;meta&amp;gt; (C++26)|url=https://en.cppreference.com/cpp/header/meta|author=cppreference.com|publisher=cppreference.com|website=cppreference.com|access-date=17 May 2026}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
import std;&lt;br /&gt;
&lt;br /&gt;
using std::string_view;&lt;br /&gt;
using std::views::filter;&lt;br /&gt;
using std::meta::access_context;&lt;br /&gt;
using std::meta::exception;&lt;br /&gt;
using std::meta::info;&lt;br /&gt;
&lt;br /&gt;
namespace meta = std::meta;&lt;br /&gt;
&lt;br /&gt;
consteval bool isNonstaticMethod(info mem) noexcept {&lt;br /&gt;
    return meta::is_class_member(mem) &amp;amp;&amp;amp;&lt;br /&gt;
        !meta::is_static_member(mem) &amp;amp;&amp;amp;&lt;br /&gt;
        meta::is_function(mem);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
consteval info findMethod(info clazz, string_view name) {&lt;br /&gt;
    for (info member : meta::members_of(clazz, access_context::current()) | filter(isNonstaticMethod)) {&lt;br /&gt;
        if (meta::has_identifier(member) &amp;amp;&amp;amp; meta::identifier_of(member) == name) {&lt;br /&gt;
            return member;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    // Note: this is std::meta::exception, not std::exception&lt;br /&gt;
    throw exception(std::format(&amp;quot;Failed to retrieve method {} from class {}&amp;quot;, name, meta::identifier_of(clazz)), ^^findMethod);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;info Clazz, const char* Name&amp;gt;&lt;br /&gt;
constexpr auto createInvokerImpl = [] -&amp;gt; auto {&lt;br /&gt;
    static constexpr info M = findMethod(Clazz, Name);&lt;br /&gt;
    static_assert(&lt;br /&gt;
        meta::parameters_of(M).size() == 0 &amp;amp;&amp;amp; meta::return_type_of(M) == ^^void,&lt;br /&gt;
        &amp;quot;Reflected method must take zero parameters and return void.&amp;quot;&lt;br /&gt;
    );&lt;br /&gt;
    return []([:Clazz:]&amp;amp; instance) -&amp;gt; void { instance.[:M:](); };&lt;br /&gt;
}();&lt;br /&gt;
&lt;br /&gt;
consteval info createInvoker(info clazz, string_view name) {&lt;br /&gt;
    return meta::substitute(&lt;br /&gt;
        ^^createInvokerImpl,&lt;br /&gt;
        { meta::reflect_constant(clazz), meta::reflect_constant_string(name) }&lt;br /&gt;
    );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Foo {&lt;br /&gt;
private:&lt;br /&gt;
    // ...&lt;br /&gt;
public:&lt;br /&gt;
    Foo() = default;&lt;br /&gt;
&lt;br /&gt;
    void printHello() const {&lt;br /&gt;
        std::println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]) {&lt;br /&gt;
    Foo foo;&lt;br /&gt;
&lt;br /&gt;
    // Without reflection&lt;br /&gt;
    foo.printHello();&lt;br /&gt;
&lt;br /&gt;
    // Through splicing&lt;br /&gt;
    foo.[:findMethod(^^Foo, &amp;quot;printHello&amp;quot;):]();&lt;br /&gt;
&lt;br /&gt;
    // Through invocation/template factory&lt;br /&gt;
    auto invokePrint = [:createInvoker(^^Foo, &amp;quot;printHello&amp;quot;):];&lt;br /&gt;
    invokePrint(foo);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
The example below is in [[C Sharp (programming language)|C#]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c#&amp;quot;&amp;gt;&lt;br /&gt;
namespace Wikipedia.Examples;&lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
class Foo&lt;br /&gt;
{&lt;br /&gt;
    // ...&lt;br /&gt;
&lt;br /&gt;
    public void PrintHello()&lt;br /&gt;
    {&lt;br /&gt;
        Console.WriteLine(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class InvokeFooExample&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        // Without reflection&lt;br /&gt;
        Foo foo = new();&lt;br /&gt;
        foo.PrintHello();&lt;br /&gt;
&lt;br /&gt;
        // With reflection&lt;br /&gt;
        object? reflectedFoo = Activator.CreateInstance(typeof(Foo));&lt;br /&gt;
        MethodInfo? method = reflectedFoo?&lt;br /&gt;
            .GetType()&lt;br /&gt;
            .GetMethod(&amp;quot;PrintHello&amp;quot;);&lt;br /&gt;
        method?.Invoke(reflectedFoo, null);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delphi, Object Pascal===&lt;br /&gt;
This [[Delphi (software)|Delphi]] and [[Object Pascal]] example assumes that a {{mono|TFoo}} class has been declared in a unit called {{mono|Unit1}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Delphi&amp;quot;&amp;gt;&lt;br /&gt;
uses RTTI, Unit1;&lt;br /&gt;
&lt;br /&gt;
procedure WithoutReflection;&lt;br /&gt;
var&lt;br /&gt;
  Foo: TFoo;&lt;br /&gt;
begin&lt;br /&gt;
  Foo := TFoo.Create;&lt;br /&gt;
  try&lt;br /&gt;
    Foo.Hello;&lt;br /&gt;
  finally&lt;br /&gt;
    Foo.Free;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&lt;br /&gt;
procedure WithReflection;&lt;br /&gt;
var&lt;br /&gt;
  RttiContext: TRttiContext;&lt;br /&gt;
  RttiType: TRttiInstanceType;&lt;br /&gt;
  Foo: TObject;&lt;br /&gt;
begin&lt;br /&gt;
  RttiType := RttiContext.FindType(&amp;#039;Unit1.TFoo&amp;#039;) as TRttiInstanceType;&lt;br /&gt;
  Foo := RttiType.GetMethod(&amp;#039;Create&amp;#039;).Invoke(RttiType.MetaclassType, []).AsObject;&lt;br /&gt;
  try&lt;br /&gt;
    RttiType.GetMethod(&amp;#039;Hello&amp;#039;).Invoke(Foo, []);&lt;br /&gt;
  finally&lt;br /&gt;
    Foo.Free;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===eC===&lt;br /&gt;
The example below is in eC:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=eC&amp;gt;&lt;br /&gt;
// Without reflection&lt;br /&gt;
Foo foo{};&lt;br /&gt;
foo.hello();&lt;br /&gt;
&lt;br /&gt;
// With reflection&lt;br /&gt;
Class fooClass = eSystem_FindClass(__thisModule, &amp;quot;Foo&amp;quot;);&lt;br /&gt;
Instance foo = eInstance_New(fooClass);&lt;br /&gt;
Method m = eClass_FindMethod(fooClass, &amp;quot;hello&amp;quot;, fooClass.module);&lt;br /&gt;
((void(*)())(void*)m.function)(foo);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Go===&lt;br /&gt;
The example below is in [[Go (programming language)|Go]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;go&amp;quot;&amp;gt;&lt;br /&gt;
import (&lt;br /&gt;
    &amp;quot;fmt&amp;quot;&lt;br /&gt;
    &amp;quot;reflect&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
type Foo struct{}&lt;br /&gt;
&lt;br /&gt;
func (f Foo) Hello() {&lt;br /&gt;
    fmt.Println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
func main() {&lt;br /&gt;
    // Without reflection&lt;br /&gt;
    var f Foo&lt;br /&gt;
    f.Hello()&lt;br /&gt;
&lt;br /&gt;
    // With reflection&lt;br /&gt;
    var fT reflect.Type = reflect.TypeOf(Foo{})&lt;br /&gt;
    var fV reflect.Value = reflect.New(fT)&lt;br /&gt;
&lt;br /&gt;
    var m reflect.Value = fV.MethodByName(&amp;quot;Hello&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    if m.IsValid() {&lt;br /&gt;
        m.Call(nil)&lt;br /&gt;
    } else {&lt;br /&gt;
        fmt.Println(&amp;quot;Method not found&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
The example below is in [[Java (programming language)|Java]]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
package org.wikipedia.examples;&lt;br /&gt;
&lt;br /&gt;
import java.lang.reflect.Method;&lt;br /&gt;
&lt;br /&gt;
class Foo {&lt;br /&gt;
    // ...&lt;br /&gt;
&lt;br /&gt;
    public void printHello() {&lt;br /&gt;
       System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class InvokeFooExample {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        // Without reflection&lt;br /&gt;
        Foo foo = new Foo();&lt;br /&gt;
        foo.printHello();&lt;br /&gt;
&lt;br /&gt;
        // With reflection&lt;br /&gt;
        try {&lt;br /&gt;
            Foo reflectedFoo = Foo.class&lt;br /&gt;
                .getDeclaredConstructor()&lt;br /&gt;
                .newInstance();&lt;br /&gt;
&lt;br /&gt;
            Method m = reflectedFoo&lt;br /&gt;
                .getClass()&lt;br /&gt;
                .getDeclaredMethod(&amp;quot;printHello&amp;quot;, new Class&amp;lt;?&amp;gt;[0]);&lt;br /&gt;
            m.invoke(reflectedFoo);&lt;br /&gt;
        } catch (ReflectiveOperationException e) {&lt;br /&gt;
            System.err.printf(&amp;quot;An error occurred: %s%n&amp;quot;, e.getMessage());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Java also provides an internal class (not officially in the [[Java Class Library]]) in [[Java Platform Module System|module]] &amp;lt;code&amp;gt;jdk.unsupported&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;sun.reflect.Reflection&amp;lt;/code&amp;gt; which is used by [[Security of the Java software platform#The sun.misc.Unsafe class|&amp;lt;code&amp;gt;sun.misc.Unsafe&amp;lt;/code&amp;gt;]]. It contains one method, {{java|static Class&amp;lt;?&amp;gt; getCallerClass(int depth);}} for obtaining the class making a call at a specified depth.&amp;lt;ref&amp;gt;{{Cite web|title=Reflection (Java Platform SE 9)|url=https://cr.openjdk.org/~jjg/java-javafx-jdk-docs/api/sun/reflect/Reflection.html|publisher=OpenJDK|website=cr.openjdk.org|access-date=10 October 2025}}&amp;lt;/ref&amp;gt; This is now superseded by using the class {{Javadoc:SE|java/lang|StackWalker.StackFrame|package=java.lang|module=java.base}} and its method {{java|Class&amp;lt;?&amp;gt; getDeclaringClass();}}.&lt;br /&gt;
&lt;br /&gt;
===Julia===&lt;br /&gt;
The example below is in [[Julia (programming language)|Julia]]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;julia-repl&amp;quot;&amp;gt;&lt;br /&gt;
julia&amp;gt; struct Point&lt;br /&gt;
           x::Int&lt;br /&gt;
           y&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
# Inspection with reflection&lt;br /&gt;
julia&amp;gt; fieldnames(Point)&lt;br /&gt;
(:x, :y)&lt;br /&gt;
&lt;br /&gt;
julia&amp;gt; fieldtypes(Point)&lt;br /&gt;
(Int64, Any)&lt;br /&gt;
&lt;br /&gt;
julia&amp;gt; p = Point(3,4)&lt;br /&gt;
&lt;br /&gt;
# Access with reflection&lt;br /&gt;
julia&amp;gt; getfield(p, :x)&lt;br /&gt;
3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Kotlin===&lt;br /&gt;
Using Java reflection:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;kotlin&amp;quot;&amp;gt;&lt;br /&gt;
package org.wikipedia.examples&lt;br /&gt;
&lt;br /&gt;
import java.lang.reflect.Method&lt;br /&gt;
&lt;br /&gt;
class Foo {&lt;br /&gt;
    // ...&lt;br /&gt;
    constructor()&lt;br /&gt;
&lt;br /&gt;
    fun printHello() {&lt;br /&gt;
        println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
fun main(args: Array&amp;lt;String&amp;gt;) {&lt;br /&gt;
    // Without reflection&lt;br /&gt;
    val foo = Foo()&lt;br /&gt;
    foo.printHello()&lt;br /&gt;
&lt;br /&gt;
    // With reflection&lt;br /&gt;
    try {&lt;br /&gt;
        // Foo::class.java retrieves a java.lang.Class&amp;lt;Foo&amp;gt;&lt;br /&gt;
        val reflectedFoo = Foo::class.java&lt;br /&gt;
            .getDeclaredConstructor()&lt;br /&gt;
            .newInstance()&lt;br /&gt;
&lt;br /&gt;
        val m: Method = reflectedFoo.javaClass&lt;br /&gt;
            .getDeclaredMethod(&amp;quot;printHello&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        m.invoke(reflectedFoo)&lt;br /&gt;
    } catch (e: ReflectiveOperationException) {&lt;br /&gt;
        System.err.printf(&amp;quot;An error occurred: %s%n&amp;quot;, e.message)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using pure Kotlin:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;kotlin&amp;quot;&amp;gt;&lt;br /&gt;
package org.wikipedia.examples&lt;br /&gt;
&lt;br /&gt;
import kotlin.reflect.full.createInstance&lt;br /&gt;
import kotlin.reflect.full.functions&lt;br /&gt;
&lt;br /&gt;
class Foo {&lt;br /&gt;
    // ...&lt;br /&gt;
    fun printHello() {&lt;br /&gt;
        println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
fun main(args: Array&amp;lt;String&amp;gt;) {&lt;br /&gt;
    // Without reflection&lt;br /&gt;
    val foo = Foo()&lt;br /&gt;
    foo.printHello()&lt;br /&gt;
&lt;br /&gt;
    // With reflection&lt;br /&gt;
    try {&lt;br /&gt;
        // Foo::class retrieves a kotlin.reflect.KClass&amp;lt;Foo&amp;gt;&lt;br /&gt;
        val kClass = Foo::class&lt;br /&gt;
        val reflectedFoo = kClass.createInstance()&lt;br /&gt;
        val function = kClass.functions.first { it.name == &amp;quot;printHello&amp;quot; }&lt;br /&gt;
        function.call(reflectedFoo)&lt;br /&gt;
    } catch (e: Exception) {&lt;br /&gt;
        System.err.printf(&amp;quot;An error occurred: %s%n&amp;quot;, e.message)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Objective-C===&lt;br /&gt;
The example below is in [[Objective-C]], implying either the [[OpenStep]] or [[Foundation Kit]] framework is used:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ObjC&amp;quot;&amp;gt;&lt;br /&gt;
// Foo class.&lt;br /&gt;
@interface Foo : NSObject&lt;br /&gt;
- (void)hello;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
// Sending &amp;quot;hello&amp;quot; to a Foo instance without reflection.&lt;br /&gt;
Foo* obj = [[Foo alloc] init];&lt;br /&gt;
[obj hello];&lt;br /&gt;
&lt;br /&gt;
// Sending &amp;quot;hello&amp;quot; to a Foo instance with reflection.&lt;br /&gt;
id obj = [[NSClassFromString(@&amp;quot;Foo&amp;quot;) alloc] init];&lt;br /&gt;
[obj performSelector: @selector(hello)];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Perl===&lt;br /&gt;
The example below is in [[Perl]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
# Without reflection&lt;br /&gt;
my $foo = Foo-&amp;gt;new;&lt;br /&gt;
$foo-&amp;gt;hello;&lt;br /&gt;
&lt;br /&gt;
# or&lt;br /&gt;
Foo-&amp;gt;new-&amp;gt;hello;&lt;br /&gt;
&lt;br /&gt;
# With reflection&lt;br /&gt;
my $class = &amp;quot;Foo&amp;quot;&lt;br /&gt;
my $constructor = &amp;quot;new&amp;quot;;&lt;br /&gt;
my $method = &amp;quot;hello&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
my $f = $class-&amp;gt;$constructor;&lt;br /&gt;
$f-&amp;gt;$method;&lt;br /&gt;
&lt;br /&gt;
# or&lt;br /&gt;
$class-&amp;gt;$constructor-&amp;gt;$method;&lt;br /&gt;
&lt;br /&gt;
# with eval&lt;br /&gt;
eval &amp;quot;new Foo-&amp;gt;hello;&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PHP===&lt;br /&gt;
The example below is in [[PHP]]:&amp;lt;ref&amp;gt;{{cite web |title=PHP: ReflectionClass - Manual |url=https://www.php.net/manual/en/class.reflectionclass.php |website=www.php.net}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Without reflection&lt;br /&gt;
$foo = new Foo();&lt;br /&gt;
$foo-&amp;gt;hello();&lt;br /&gt;
&lt;br /&gt;
// With reflection, using Reflections API&lt;br /&gt;
$reflector = new ReflectionClass(&amp;quot;Foo&amp;quot;);&lt;br /&gt;
$foo = $reflector-&amp;gt;newInstance();&lt;br /&gt;
$hello = $reflector-&amp;gt;getMethod(&amp;quot;hello&amp;quot;);&lt;br /&gt;
$hello-&amp;gt;invoke($foo);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
The example below is in [[Python (programming language)|Python]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Foo:&lt;br /&gt;
    # ...&lt;br /&gt;
    def print_hello(self) -&amp;gt; None:&lt;br /&gt;
        print(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    # Without reflection&lt;br /&gt;
    obj: Foo = Foo()&lt;br /&gt;
    obj.print_hello()&lt;br /&gt;
&lt;br /&gt;
    # With reflection&lt;br /&gt;
    obj: Foo = globals()[&amp;quot;Foo&amp;quot;]()&lt;br /&gt;
    _ = getattr(obj, &amp;quot;print_hello&amp;quot;)()&lt;br /&gt;
&lt;br /&gt;
    # With eval&lt;br /&gt;
    eval(&amp;quot;Foo().print_hello()&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===R===&lt;br /&gt;
The example below is in [[R (programming language)|R]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;r&amp;quot;&amp;gt;&lt;br /&gt;
# Without reflection, assuming foo() returns an S3-type object that has method &amp;quot;hello&amp;quot;&lt;br /&gt;
obj &amp;lt;- foo()&lt;br /&gt;
hello(obj)&lt;br /&gt;
&lt;br /&gt;
# With reflection&lt;br /&gt;
class_name &amp;lt;- &amp;quot;foo&amp;quot;&lt;br /&gt;
generic_having_foo_method &amp;lt;- &amp;quot;hello&amp;quot;&lt;br /&gt;
obj &amp;lt;- do.call(class_name, list())&lt;br /&gt;
do.call(generic_having_foo_method, alist(obj))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
The example below is in [[Ruby (programming language)|Ruby]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
# Without reflection&lt;br /&gt;
obj = Foo.new&lt;br /&gt;
obj.hello&lt;br /&gt;
&lt;br /&gt;
# With reflection&lt;br /&gt;
obj = Object.const_get(&amp;quot;Foo&amp;quot;).new&lt;br /&gt;
obj.send :hello&lt;br /&gt;
&lt;br /&gt;
# With eval&lt;br /&gt;
eval &amp;quot;Foo.new.hello&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
The example below is in [[Rust (programming language)|Rust]] (using [[Macro (computer science)|procedural macros]]).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rust&amp;quot;&amp;gt;&lt;br /&gt;
// A basic macro that registers a method name string to an actual method call&lt;br /&gt;
macro_rules! invoke_method {&lt;br /&gt;
    ($instance:expr, $method_name:expr) =&amp;gt; {&lt;br /&gt;
        match $method_name {&lt;br /&gt;
            &amp;quot;print_hello&amp;quot; =&amp;gt; $instance.print_hello(),&lt;br /&gt;
            _ =&amp;gt; eprintln!(&amp;quot;An error occurred: Method not found.&amp;quot;),&lt;br /&gt;
        }&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
struct Foo;&lt;br /&gt;
&lt;br /&gt;
impl Foo {&lt;br /&gt;
    fn print_hello(&amp;amp;self) {&lt;br /&gt;
        println!(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
fn main() {&lt;br /&gt;
    let foo = Foo;&lt;br /&gt;
&lt;br /&gt;
    // Normal call sequence&lt;br /&gt;
    foo.print_hello();&lt;br /&gt;
&lt;br /&gt;
    // Reflection-style sequence via compile-time mapping&lt;br /&gt;
    let method_to_call = &amp;quot;print_hello&amp;quot;;&lt;br /&gt;
    invoke_method!(foo, method_to_call);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Swift===&lt;br /&gt;
[[Swift (programming language)|Swift]] reflection is read-only, and thus dynamic invocation is only possible through [[Objective-C]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;swift&amp;quot;&amp;gt;&lt;br /&gt;
import Foundation&lt;br /&gt;
&lt;br /&gt;
class Foo: NSObject {&lt;br /&gt;
    @objc func printHello() {&lt;br /&gt;
        print(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class InvokeFooExample {&lt;br /&gt;
    static func main() {&lt;br /&gt;
        // Without reflection&lt;br /&gt;
        let foo = Foo()&lt;br /&gt;
        foo.printHello()&lt;br /&gt;
&lt;br /&gt;
        // With &amp;quot;reflection&amp;quot; (Objective-C runtime)&lt;br /&gt;
        let reflectedFoo = Foo()&lt;br /&gt;
&lt;br /&gt;
        let selector = #selector(Foo.printHello)&lt;br /&gt;
&lt;br /&gt;
        if reflectedFoo.responds(to: selector) {&lt;br /&gt;
            reflectedFoo.perform(selector)&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Swift&amp;#039;s reflection system, with &amp;lt;code&amp;gt;Swift.Mirror&amp;lt;/code&amp;gt;, is much more limited in scope:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;swift&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import Foundation&lt;br /&gt;
&lt;br /&gt;
class Foo {&lt;br /&gt;
    func printHello() {&lt;br /&gt;
        print(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
let foo = Foo()&lt;br /&gt;
&lt;br /&gt;
let mirror = Mirror(reflecting: foo)&lt;br /&gt;
&lt;br /&gt;
print(type(of: foo)) // Foo&lt;br /&gt;
print(mirror.children.count) // Properties only&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Xojo===&lt;br /&gt;
The following is an example using [[Xojo]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
&amp;#039; Without reflection&lt;br /&gt;
Dim fooInstance As New Foo&lt;br /&gt;
fooInstance.PrintHello&lt;br /&gt;
&lt;br /&gt;
&amp;#039; With reflection&lt;br /&gt;
Dim classInfo As Introspection.Typeinfo = GetTypeInfo(Foo)&lt;br /&gt;
Dim constructors() As Introspection.ConstructorInfo = classInfo.GetConstructors&lt;br /&gt;
Dim fooInstance As Foo = constructors(0).Invoke&lt;br /&gt;
Dim methods() As Introspection.MethodInfo = classInfo.GetMethods&lt;br /&gt;
For Each m As Introspection.MethodInfo In methods&lt;br /&gt;
  If m.Name = &amp;quot;PrintHello&amp;quot; Then&lt;br /&gt;
    m.Invoke(fooInstance)&lt;br /&gt;
  End If&lt;br /&gt;
Next&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[List of reflective programming languages and platforms]]&lt;br /&gt;
* [[Mirror (programming)]]&lt;br /&gt;
* [[Programming paradigm]]s&lt;br /&gt;
* [[Self-hosting (compilers)]]&lt;br /&gt;
* [[Self-modifying code]]&lt;br /&gt;
* [[Type introspection]]&lt;br /&gt;
* [[typeof]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
=== Citations ===&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
{{refbegin}}&lt;br /&gt;
* Jonathan M. Sobel and Daniel P. Friedman. [https://web.archive.org/web/20100204091328/http://www.cs.indiana.edu/~jsobel/rop.html &amp;#039;&amp;#039;An Introduction to Reflection-Oriented Programming&amp;#039;&amp;#039;] (1996), [[Indiana University]].&lt;br /&gt;
* [https://www.codeproject.com/Articles/674455/Anti-Reflector-NET-Code-Protection Anti-Reflection technique using C# and C++/CLI wrapper to prevent code thief]&lt;br /&gt;
{{refend}}&lt;br /&gt;
&lt;br /&gt;
==Further reading==&lt;br /&gt;
* Ira R. Forman and Nate Forman, &amp;#039;&amp;#039;Java Reflection in Action&amp;#039;&amp;#039; (2005), {{ISBN|1-932394-18-4}}&lt;br /&gt;
* Ira R. Forman and Scott Danforth, &amp;#039;&amp;#039;Putting Metaclasses to Work&amp;#039;&amp;#039; (1999), {{ISBN|0-201-43305-2}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://www-master.ufr-info-p6.jussieu.fr/2007/Ajouts/Master_esj20_2007_2008/IMG/pdf/malenfant-ijcai95.pdf Reflection in logic, functional and object-oriented programming: a short comparative study]&lt;br /&gt;
* [https://web.archive.org/web/20100204091328/http://www.cs.indiana.edu/~jsobel/rop.html An Introduction to Reflection-Oriented Programming]&lt;br /&gt;
* [http://www.laputan.org/#Reflection Brian Foote&amp;#039;s pages on Reflection in Smalltalk]&lt;br /&gt;
* [http://docs.oracle.com/javase/tutorial/reflect/index.html Java Reflection API Tutorial] from Oracle&lt;br /&gt;
{{Programming paradigms navbox}}&lt;br /&gt;
{{Types of programming languages}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Reflection (Computer Programming)}}&lt;br /&gt;
[[Category:Programming constructs]]&lt;br /&gt;
[[Category:Programming language comparisons]]&lt;br /&gt;
&amp;lt;!-- Hidden categories below --&amp;gt;&lt;br /&gt;
[[Category:Articles with example BASIC code]]&lt;br /&gt;
[[Category:Articles with example C code]]&lt;br /&gt;
[[Category:Articles with example C Sharp code]]&lt;br /&gt;
[[Category:Articles with example Java code]]&lt;br /&gt;
[[Category:Articles with example JavaScript code]]&lt;br /&gt;
[[Category:Articles with example Julia code]]&lt;br /&gt;
[[Category:Articles with example Lisp (programming language) code]]&lt;br /&gt;
[[Category:Articles with example Objective-C code]]&lt;br /&gt;
[[Category:Articles with example Pascal code]]&lt;br /&gt;
[[Category:Articles with example Perl code]]&lt;br /&gt;
[[Category:Articles with example PHP code]]&lt;br /&gt;
[[Category:Articles with example Python (programming language) code]]&lt;br /&gt;
[[Category:Articles with example R code]]&lt;br /&gt;
[[Category:Articles with example Ruby code]]&lt;/div&gt;</summary>
		<author><name>~2026-57829-28</name></author>
	</entry>
</feed>