How can we find size of the object ?
Answer Posted / lachha g
you can use Instrumentation class.
use long getObjectSize(Object objectToSize) method.
It returns amount of storage consumed by the specified object.
package Test;
import java.lang.instrument.Instrumentation;
public class ObjectSize {
private int x;
private int y;
ObjectSize(int x, int y){
this.x=x;
this.y=y;
}
public static void main(String [] args) {
ObjectSize obj= new ObjectSize(2,4);
System.out.println(Test.getObjectSize(obj));
}
}
class Test {
private static Instrumentation instrumentation;
public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}
public static long getObjectSize(Object o) {
return instrumentation.getObjectSize(o);
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Is java an open source?
Can a constructor have different name than a class name in java?
What is the function of java?
Difference between throw and throws?
Define array. Tell me about 2-D array.
How do you ensure that n threads can access n resources without deadlock?
Is 0 an even number?
Is empty set an element of empty set?
What is this keyword in java?
How do you do absolute value in java?
What is byte code and why is it important to java’s use for internet programming?
Is double bigger than float?
What is a treeset class?
How do you represent a space in regex java?
What about features of local inner class?