いくつかのタイプのアレイをシリアル化して、メモリで最悪のものを見つけてください。だから私はジェネリック型をシリアル化する関数を作成し、int calcul(T a)
それはintのサイズを返します。
public class NewClass<T> {
public static void main(String[] args) throws IOException {
byte[] tabByte = new byte[56666];
Byte[] tabByte2 = new Byte[56666];
int[] tabInt = new int[56666];
ArrayList<Byte> arr=new ArrayList<Byte>(56666);
System.out.println("size array byte[]"+calcul(tabByte));
System.out.println("size array Byte[]"+calcul(tabByte2));
System.out.println("size array int[]"+calcul(tabInt));
System.out.println("size array ArrayList<Byte>"+calcul(arr));
}
static int calcul(T a) throws IOException {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(byteOutput);
stream.writeObject(a);
int a = byteOutput.toByteArray().length;
stream.flush();
stream.close();
byteOutput.flush();
byteOutput.close();
return a;
}
}
しかし、私はこのエラーがあります
non-static type variable T cannot be referenced from a static context
ジェネリック変数を静的にしてプログラムを実行するにはどうすればよいですか?