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 are the supported platforms by java programming language?
What is the functionability stubs and skeletons?
Is an integer an object?
What are the topics in advance java?
Discuss 2D arrays.
How do you end a program?
What are the two parts of a conditional statement?
Can arraylist hold different types java?
What does the @override annotation do?
What is an infinite loop?
What are the various access specifiers for java classes?
Explain the transient field modifier?
Tell me about your ability to work under pressure
Where is stringbuffer stored?
Can inner class extend any class?