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
How to provide security in java
What is final modifier?
When do we use synchronized blocks and advantages of using synchronized blocks?
Which class is the superclass for all the classes?
what is bmg file and how to create that files?what will it contailn?
What is the collection interface?
What are passing parameters?
Why does java have two ways to create child threads?
What is the replace tool?
Why are pointers not secure?
What classes of exceptions may be caught by a catch clause in java programming?
What is defined as false sharing in the context of multithreading?
What is return type in java?
How do you read a char in java?
What are the 4 types of research methods?