java.lang.reflect.*
Write Dynamically Reusable Code in Java
As a Java programmer, if we know how reflection works, we can save a lot of time and effort. Instead of writing versions of the same code over and over again, we can write a single method that does what we want in a general way. In this course we start with the basics, then show how reflection works with the more modern language features such as sealed classes and records. We also show how arrays can be manipulated and created via reflection. Lastly, we show MethodHandle and VarHandle. Learn from hands-on exercises that are followed by demos revealing the solutions.
Benefits of Course
- Save programming time by writing dynamic solutions to reoccurring problems.
- Learn how dynamic coding via reflection affects Java performance and correctness.
- A well-rounded Java programmer should know reflection, when to use it, and more importantly, when not to use it.
What you'll learn and how you can apply it
By the end of the course, you'll understand:
- Basic reflection: Class, Method, Field, Constructor
- More advanced reflection concepts: generics, records, sealed classes, nested classes, modules
- Deep reflection in Java, which allows changes to private final fields
- How to manipulate arrays with reflection
- MethodHandle and VarHandle
And you'll be able to:
- Inspect a class and find methods, fields and contructors at runtime
- Call methods, change fields, even if they are private
- Write more general code that can be reused in many different contexts
- Understand VarHandles and MethodHandles and know when to use them
- Know how sealed classes and records can be inspected via reflection
This course is for you because...
- You want to be considered a guru by your colleagues and peers, writing "magical" Java code that dynamically adapts itself to change.
- You want to save time in your development by writing highly reusable code.
- You are in the top tier of developers and want to learn how to write libraries and frameworks
Who should take this course?
- Students should be very familiar with Java 11, understanding data structures, object orientation, recursion and modern Java syntax.
- Prior experience with reflection is a bonus, but not necessary.
Your Instructor
Heinz Kabutz is the author of The Java Specialists’ Newsletter, a publication enjoyed by tens of thousands of Java experts in over 150 countries. He has been a Java Champion since 2005.
Course Curriculum
-
Preview1.1. Welcome (2:51)
-
Preview1.2. Why learn reflection? (3:46)
-
Preview1.3. Class Class (30:00)
-
Preview1.3. Walkthrough Exercise 1A (4:32)
-
Preview1.3.1. Method (22:56)
-
Start1.3.1. Walkthrough Exercise 1B (5:22)
-
Start1.3.2. Constructor (11:41)
-
Start1.3.2. Walkthrough Exercise 1C (4:21)
-
Start1.3.3. Generics (4:59)
-
Start1.4. Nested Classes (3:14)
-
Start1.5. Sealed classes (3:53)
-
Start1.5. Walkthrough Exercise 1D (4:05)
-
Start1.6. Records (9:36)
-
Start1.6. Walkthrough Exercise 1E (21:19)
Frequently Asked Questions
Thank you so much for your interest in this course. If you have any questions, please contact Heinz Kabutz.