Java 方法组合数组列表:可变数量的参数

Java methods combine a list of arrays: variable number of arguments

一种组合数组列表的方法:可变数量的数组。 方法签名

public static <T> T[] combine(T[] ... a) {
    ...
} 

byte[] a = [];
byte[] b = [];
byte[] c = [];
combine(a, b, c);   // compiling error

为可变数量的数组定义方法签名的正确方法是什么。谢谢

那是因为你不能用 T 替换基本类型。

尝试使用包装器 class Byte:

public static void main(String[] args) {
  Byte[] a = new Byte[]{0x0};
  Byte[] b = a;
  Byte[] c = a;
  combine(a, b, c); 
}
public static <T> T[] combine(T[] ... a) {
  //do your magic here
} 

当然这段代码并没有组合数组,但是方法调用编译。