Skip to main content
PreparationZone Logo
PrepZone

Reflection & Strong Encapsulation

setAccessible cost, MethodHandle basics and what JDK internals block since Java 9.

Pass checkpoint below

Reflection API

Java
public class Example {
    public static void main(String[] args) {
        Method m = List.class.getDeclaredMethod("size");
            m.setAccessible(true); // may fail on JDK internals
    }
}

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Test yourself

Answer these before moving on — recall is what makes it stick.