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.
Table of Contents
module-info.java
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; }
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. That’s the only way we can improve.