الانعكاس
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
inspect and invoke code at runtime.
الموضوعات المخطط لها
Class<?>gives fields, methods, constructors, annotations, and modifiers.- Invoke with
Method.invoke; read fields withField.get(needssetAccessible(true)for private members, and may be blocked by modules). - Frameworks use it for dependency injection, serialization, and mapping.
- Costs: slower than direct calls, bypasses compile-time checks, and can break encapsulation.
- Avoid in hot paths; cache
Methodobjects or useMethodHandle.
تفاصيل المخطط المبدئي
عرض عملي
for (Method m : Product.class.getDeclaredMethods()) {
System.out.println(m.getName() + " " + m.getReturnType());
}اختبر فهمك
Why avoid reflection in hot loops?
أظهر الإجابة
Slower, and checks move from compile time to runtime.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.