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.

module-info.java

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;
}

Main.java

package firstmodule.com.javadeveloperzone;

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.
Yes
No

Leave a Reply

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