Java:
public class MetadataReader {
public void readMetadata() {
// Get the stack trace
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// The third element in the stack trace represents the caller
StackTraceElement caller = stackTrace[2];
System.out.println("Called from: " + caller.getClassName() + "." + caller.getMethodName());
}
}
public class ExternalClass {
public void externalFunction() {
MetadataReader reader = new MetadataReader();
reader.readMetadata(); // Call the method
}
}
public class Main {
public static void main(String[] args) {
ExternalClass external = new ExternalClass();
external.externalFunction();
}
}