I am trying to find a way to get the name of the classes that import my custom library. Thus, if Class A imports libcustomA then libcustomA should know Class A's name at runtime. Thus, I can use the Class.forName(class A's name) to get a new instance of class A and do reflections on that class. I do not want to use a variable for Class A's name and have Class A provide me it's name. I want to do it more professionally than that like how spring and hibernate do it. Is there a way that I can ask the JVM for the class that is importing my library or something similar to that. Thank you in advance for your answers.
Asked
Active
Viewed 32 times
1 Answers
0
No you cannot get the information of which class imported
your class
, you need to get a reference of the client class inside yours.
May be you can create an interface
and ask the client ClassA
to implement
the interface and in your class from libcustomA
have a method which takes the interface
,and the client
ClassA
should invoked your method sending its reference this
.

Sajan Chandran
- 11,287
- 3
- 29
- 38