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
what is the swingutilities.invokelater(runnable) method for? : Java thread
What must a class do to implement an interface in java programming?
What is procedure writing?
Why are getters and setters used?
What are keywords and reserved words in java?
What are serialization and deserialization?
Write a program to show whether a graph is a tree or not using adjacency matrix.
How do you represent a space in regex java?
What does you mean in math?
Why are there no global variables in java?
What is variable in java?
How is hashcode calculated in java?
What is starvation?
What is the difference between synchronized and synchronized block?
What does g mean in regex?