sizeof in java

Solutions on MaxInterview for sizeof in java by the best coders in the world

showing results for - "sizeof in java"
Abigail
16 Mar 2018
1/* There is no such method in the standard Java SE class library.
2All primitive values have a predefined size, e.g. int is 4 bytes, 
3char is 2 byte, short is 2 byte, long and float is 8 byte, and so on.
4  
5  A class to count sizeof primitive */
6    
7public class PrimitiveSizes {
8   public static int sizeof(byte b) { return 1; } 
9   public static int sizeof(short s) { return 2; }
10   // etcetera
11}