In this article, we are going to explain, How to use sun.reflect package in jdk9/java-9?

sub.reflect is an important API to access get loader or caller class object. In Java 9, it has been moved to jdk.unsupported modules. Here is an example of how to access sun.reflect package.

Here jdk.unsuppored module in which sun.reflect API has been moved. I am not sure why this module is named unsupported module !!!

module firstmodule {
    requires jdk.unsupported;

import sun.reflect.Reflection;
public class Main {
    public static void main(String[] args) {
        Class c = Reflection.getCallerClass(3);


Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *