How to obtain instance of Instrumentation in Java
问题 I am trying to write a simply ObjectUtils class that contains a variety of utility methods for all Objects. I would like to have one of them called getObjectSize(Object) where you pass it an instantiated Object and it returns the Object's size in memory: public class ObjectUtils { private static volatile Instrumentation instrumentation; public static final long getObjectSize(final Object p_oToGauge) { return instrumentation.getObjectSize(p_oToGauge); } } However, it seems that in order to