Sometimes, when debugging, we want to know that a specific generic class is called by those classes. At this time, we can use
Sun. Reflect. reflection. getcallerclass (2); to get the class name that calls a specific class. Example:
I want to know the classes that call getmemory. You can do this.
/*
* Created on 2005-1-31
*
*/
Package com. tesge;
/**
* @ Author tesge
*
*/
Public class getmemory
{
Public getmemory ()
{
// Parameter 2 to obtain who called this class
System. Out. println ("-------- is:" + sun. Reflect. reflection. getcallerclass (2 ));
}
Public static void main (string [] ARGs)
{
System. Out. println ("total memory is:" + runtime. getruntime (). totalmemory ()/1024 );
System. Out. println ("free memory is:" + runtime. getruntime (). freememory ()/1024 );
// Obtain the reflection class itself, -------- is: Class sun. Reflect. Reflection
System. Out. println ("-------- is:" + sun. Reflect. reflection. getcallerclass (0 ));
// Class name. Here is -------- is: Class com. tesge. getmemory
System. Out. println ("-------- is:" + sun. Reflect. reflection. getcallerclass (1 ));
}
}