How do I know that some classes call a specific class?

Source: Internet
Author: User

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 ));
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.