反射是程式在運行時檢查、修改自身結構與行為的能力。核心功能包含:
| 功能 | Java | C# (.NET) | PHP | JavaScript |
|---|---|---|---|---|
| 類別元資訊 | Class<T> | Type | ReflectionClass | constructor / Object.getOwnPropertyDescriptors |
| 方法 | Method | MethodInfo | ReflectionMethod | Function.prototype / Reflect.apply |
| 欄位/屬性 | Field | FieldInfo / PropertyInfo | ReflectionProperty | Object.getOwnPropertyDescriptors |
| 建構子 | Constructor | ConstructorInfo | ReflectionMethod('__construct') | new.target / Reflect.construct |
| 註解/屬性 | Annotation | Attribute | ReflectionClass::getAttributes (PHP 8+) | 無原生支援,需裝飾器模擬 |
java.lang.reflect (20+ 類)、Apache Commons Lang ReflectUtils、Spring ReflectionUtilsSystem.Reflection 命名空間、FastMember、Mono.Cecil (IL 級操作)ReflectionClass、ReflectionMethod、Doctrine AnnotationsReflect API、Proxy、TypeScript 裝飾器Assembly.LoadFile() 載入外部 DLL;Java 僅支援 ClassLoader 載入 JAR/Class 檔TypeToken 等技巧獲取System.Reflection.Emit 支援運行時發射 IL;Java 需 ASM/ByteBuddy 操作位元碼IReflector、ITypeInfo、IMemberInfo