I wanted to cast a series of objects in an array to different types based upon user preferences.
Is it possible to reference primitive-types from an array for casting?
public void MakeByteBuffer(float x, float y, float z) {
xyz[0] = x;
xyz[1] = y;
xyz[2] = z;
byteBufferSend.rewind();
for (int i = 0; i < whatToSendVarArray.length; i++) {
switch (whatToSendTypeArray[whatToSendVarArray[i]]) {
case 0:// byte
byteBufferSend.put((byte) xyz[whatToSendVarArray[i]]);
break;
case 1:// short
byteBufferSend
.putShort((short) xyz[whatToSendVarArray[i]]);
break;
case 2:// int
byteBufferSend
.putInt((int) xyz[whatToSendVarArray[i]]);
break;
// Plus more types...
}
byteArrayDataToSend = byteBufferSend.array();
}
}
Ideally I would like:
typeArray={byte,short,int,long,float,double};
byteBufferSend.put???((typeArray[i]) xyz[whatToSendVarArray[i]]);
What is the best practice?