How to know that there are those classes to call a particular class

xiaoxiao2021-03-06  41

Sometimes, we want to know that a particular general class is called when commissioning, and we can use Sun.Reflect.Reflection.getCallerClass (2); to get the class name of the call. Example: I I want to know those classes called getMemory, which can be done / * created on 2005-1-31 * / package com.tesge;

/ ** * @Author Tesge * * / public class getMemory {

Public getMemory () {// Parameter 2 When you call 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); // Get the Reflection class itself, -------- Is: class sun.reflect.reflection system.out.println ("-------- IS : " Sun.Reflect.Reflection.getCallerClass (0)); // Class itself. Here is -------- Is: class com.tesge.getMemory System.out.println (" - ------ Is: " Sun.Reflect.Reflection.getCallerclass (1));}}

转载请注明原文地址:https://www.9cbs.com/read-62218.html

New Post(0)