I want store a list of doubles and ints to a ByteBuffer, which asks for a size to allocate. I'd like to write something like C's syntax
int size=numDouble*sizeof(double)+numInt*sizeof(int);
But there is no sizeof
in Java. What is the best practice to calculate the size in byte? Should I hardcode it?
See @Frank Kusters' answer, below!
(My original answer here was for Java versions < 8.)