sub.reflect is important API to access get loader or caller class object. In java 9 its has been move to jdk.unsupported modules. Here is example of how to access sun.reflect package.

Here jdk.unsuppored module in which sun.reflect API has been more. I am not too much clear why is unsuppoered 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?
Let us know, if you liked the post. Only in this way, we can improve us.

Leave a Reply

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