I would like to have a debugging aid, telling me in what instance of an own class the error happened.
public class MyApp {
MyClass myClass1= new MyClass(...);
MyClass myClass2= new MyClass(...);
MyClass myClassN= new MyClass(...);
}
So MyClass should tell me, whether it is instance myClass1, myClass2 or myClassN which is causing the error.
I have found examples how to access a caller class and how to access variable names via reflection. But in order to use Class.getDeclaredField(String name)
you have to know the name of the variable beforehand.
I could, of course, pass the instance name as a string, but if the name could be elicited with code, it would not only be nicer, but also a help in future unforeseen bugs.