Перейти к содержимому

Java Reflection and JNI: Plugins, Pitfalls and the FFM API | Effective Java L62

The Modern SDE

0:00 / 0:00

Java Reflection and JNI: Plugins, Pitfalls and the FFM API | Effective Java L62

1 просмотр · 15 ч назад
The Modern SDE
1,35 тыс. подписчиков
1 просмотр · 15 ч назад
Lecture 62 of the Effective Java Masterclass by Engineer X · Part 8: General Programming. In this lecture • A payment-gateway plugin loaded by class name: ClassNotFound, ClassCast, NoSuchMethod and InvocationTarget failures, run for real • What core reflection does (Class, Constructor, Method, Field) and what it costs: no compile-time checks, verbose code, slower calls • Reflect only to instantiate, then use an interface: asSubclass and one ReflectiveOperationException catch • A legitimate use: compile against the oldest dependency version, reach newer APIs reflectively with a fallback • Modern Java: strong encapsulation (16, 17), InaccessibleObjectException and --add-opens; records and sealed types are reflectable; ServiceLoader • Native methods: historic uses, why they're rarely worth it now, and their costs • The FFM API: a preview in Java 21 calling C's strlen, final in Java 22 • Interview: loading a gateway plugin by class name, and what Java 16 and 17 changed Chapters 0:00 A gateway that never loaded 0:49 What reflection gives, and costs 1:28 Reflect once, then use the interface 2:52 Modern Java: strong encapsulation 4:19 Native code: rarely worth it 6:10 In the interview 6:57 Recap 7:21 Quiz Follows the topics of Effective Java, 3rd edition, by Joshua Bloch (Item 65: Prefer interfaces to reflection, Item 66: Use native methods judiciously). Every explanation, example and line of code in this lecture is original. Previous lecture: L061 Program to Interfaces in Java: List vs ArrayList and SequencedSet Next lecture: L063 Java Performance Optimization: Measure First, Fix the Algorithm #Java #EffectiveJava #JavaInterview #SeniorJavaDeveloper #JavaBestPractices #EngineerX #JavaReflection #JNI #JavaFFM