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
List implementations of list interface?
Difference between Linked list and Queue?
Can two objects have same hashcode?
What is generic class?
What is a lightweight component?
Compare overloading and overriding?
How do you escape a string?
What is use of functional interface in java 8? Explain
Is java a software?
Write a program in java to create a doubly linked list containing n nodes.
What is a boolean used for?
What are internal and external variables?
Can array grow dynamically in java?
Explain the difference between static and dynamic binding in java?
why not override thread to make a runnable? : Java thread