image

Good afternoon from Crete!

Our new course on Java Reflection is now available in our Teachable school. I recorded it over the last two weeks. It will take you about 4-5 hours to get through, including the exercises. We always recommend that you do all the exercises, because it will help you understand the concepts so much better.

Until Friday the 23rd Sep 2022, we have a 50% early-bird special on the course: FIFTY-OFF-EARLY-BIRD

This course is part of our Java Specialists Superpack '22, in case you'd like to use up some of your training budget for the full pack.

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

Every section has exercises to make sure that you understand exactly how to use the various reflection constructs. And comments are enabled for each lecture, thus you can ask as much as you like.

Detailed Outline

Segment 1: Introduction to Reflection

  • Welcome
  • Why learn reflection?
  • Class Class
  • Method
  • Field
  • Constructor
  • Generics
  • Nested classes
  • Sealed classes
  • Records

Segment 2: Deep Reflection

  • Making private members accessible
  • Dealing with exceptions
  • Performance considerations

Segment 3: Arrays

  • Accessing elements
  • Creating new

Segment 4: java.lang.invoke

  • MethodHandles.Lookup
  • privateLookupIn()
  • MethodHandle
  • MethodType
  • VarHandle
  • Converting from Method to MethodHandle

We also have several free Java newsletters that cover reflection, such as:

Related Newsletters

  • Issue 298 Finding Permitted Subclasses
    Sealed classes show us which subclasses they permitted. Unfortunately there is no way to do this recursively. In this newsletter we show how to navigate the sealed class hierarchy and write a ClassSpliterator that can then create a Stream of classes.
  • Issue 291 Snakes and Ladders
    "Would you like to play with me?" - Summer holidays are a good time to relax and whip out a board game or two. In this newsletter we explore a children's favourite - snakes and ladders, with a simulation written in Java.
  • Issue 287 @PolymorphicSignature
    MethodHandles annotate the invoke() methods with @PolymorphicSignature. In this newsletter we see how this can help to avoid unnecessary object creation.
  • Issue 275 EnhancedStream with Dynamic Proxy
    In our previous newsletter we enhanced Java 8 Streams by decorating them with an EnhancedStream class. The code had a lot of repetition, which often leads to bugs if written by hand. In this newsletter we use a dynamic proxy to create an Enhance...
  • Issue 274 EnhancedStream
    Java 8 Streams have a rather narrow-minded view of what makes objects distinct. In this newsletter, we enhance Streams to allow a more flexible approach for deciding uniqueness.
  • Issue 273 Truly Public Methods
    Class.getMethods() returns all the public methods in this class and the classes in its ancestry. However, we cannot necessarily call these methods, for example if they are declared in a private inner class or a lambda. In this newsletter we atte...
  • Issue 272 Hacking Enums Revisited
    In a previous newsletter, we looked at how we could dynamically add new enums and also rewire affected switch statements. Due to improvements in Java security, our old approach needs to be updated for Java 12.
  • Issue 270 Excursions into Deduplication
    When are Strings deduplicated? How can we find out whether they are of any benefit in our application? How much does it cost in terms of CPU? We try to show you how we can get this from the deduplication statistics provided by the JVM.
  • Issue 254 Big O Cost of Class.getMethod()
    We now look at why the best-case scenario for a getMethod() call is O(n), not O(1) as we would expect. We also discover that the throughput of getMethod() has doubled in Java 9.
  • Issue 249 @Contended @since 9
    Java 9 is more strict about what system internal classes we can use. So how can we use @Contended in Java 9? This article shows you how.
  • Issue 242 Concurrency Puzzle Explained, Solved With StampedLock
    Most programmers had a blind spot with the statement "arr[size++] = e;" We somehow think that size will be updated after the assignment. In this newsletter we look at this basic concurrency bug and also present a solution in the form of the Java...
  • Issue 237 String Compaction
    Java 6 introduced a mechanism to store ASCII characters inside byte[] instead of a char[]. This feature was removed again in Java 7. However, it is coming back in Java 9, except this time round, compaction is enabled by default and byte[] is alw...
  • Issue 235 Checking HashMaps with MapClashInspector
    Java 8 HashMap has been optimized to avoid denial of service attacks with many distinct keys containing identical hash codes. Unfortunately performance might degrade if you use your own keys. In this newsletter we show a tool that you can use to...
  • Issue 229 Cleaning ThreadLocals
    ThreadLocals should in most cases be avoided. They can solve some tough problems, but can introduce some nasty memory leaks, especially if the ThreadLocal class or value refer to our own classes, not a system class. In this newsletter we show so...
  • Issue 228 Extracting Real Task from FutureTask
    ExecutorService allows us to submit either Callable or Runnable. Internally, this is converted to a FutureTask, without the possibility of extracting the original task. In this newsletter we look at how we can dig out the information using refle...
  • Issue 185 Book Review: Java: The Good Parts
    In his latest book, Jim Waldo describes several Java features that he believes make Java "good". A nice easy read, and I even learned a few new things from it.
  • Issue 175 Creating Objects Without Calling Constructors
    De-Serialization creates objects without calling constructors. We can use the same mechanism to create objects at will, without ever calling their constructors.
  • Issue 168 The Delegator
    In this newsletter we show the reflection plumbing needed for writing a socket monitor that sniffs all the bytes being sent or received over all the Java sockets. The Delegator is used to invoke corresponding methods through some elegant guesswork.
  • Issue 167 Annotation Processing Tool
    In this newsletter we answer the question: "How do we force all subclasses to contain a public no-args constructor?" The Annotation Processing Tool allows us to check conditions like this at compile time, rather than only at runtime.
  • Issue 161 Of Hacking Enums and Modifying "final static" Fields
    The developers of the Java language tried their best to stop us from constructing our own enum instances. However, for testing purposes, it can be useful to temporarily add new enum instances to the system. In this newsletter we show how we can ...
  • Issue 144 Book Review: Java Puzzlers
    Experienced Java programmers will love the Java Puzzlers book by Josh Bloch and Neal Gafter, both well known Java personalities. In this newsletter, we look at two of the puzzles as a teazer for the book.
  • Issue 142 Instrumentation Memory Counter
    Memory usage of Java objects has been a mystery for many years. In this newsletter, we use the new instrumentation API to predict more accurately how much memory an object uses. Based on earlier newsletters, but revised for Java 5 and 6.
Profile Image Heinz Kabutz
Director
Cretesoft Limited
[email protected]
+306975595262 - Work
www.javaspecialists.eu

Unsubscribe

Cretesoft Limited 77 Strovolos Ave Strovolos, Lefkosia 2018 Cyprus