java byte[] 实现C语言的常量结构体数组
有时候,想和C语言一样,把数据直接保存成常量数组,这个很方便快捷,如:
typedef struct
{
int a;
} DataStruct;
const DataStruct tab[] =
{
{1},
{2},
};
那么,在java里怎么实现呢?
class AnsData {
public byte[] req_buf;
public byte[] ans_buf;
public AnsData(byte[] str_in, byte[] str2){
req_buf = str_in;
ans_buf = str2;
}
};
AnsData[] AnsDataLib = {
new AnsData(new byte[]{0x01, 0x03}, new byte[]{0x43,0x00}),
new AnsData(new byte[]{0x01,0x07}, new byte[]{0x47,0x00}),
};