Th3lmuu90 Th3lmuu90 - 26 days ago 7
Android Question

How to know in Java which class declared an object

Let's imagine I have the following class

public class xyz {
public xyz(string mystring123) {
//mystring123 was declared in class abc, but how can I check that?
}
}


What I would like to know if in which class the string I receive in the constructor was declared.

Is this even possible? I don't have any control over the class abc, only the class xyz.

Answer

I can't offer you exactly what you're looking for, but I can suggest something "in the same ballpark."

You can use...

Thread.currentThread().getStackTrace();

to get an array of StackTraceElement objects representing the current call stack. This knowledge may help you understand more about what's happening when your xyz class is invoked.

Also if you can connect a decent strep-through debugger, you can see the stack trace and more.