我已将Netbeans设置为在我的Java代码中显示未经检查的警告,但我无法理解以下行中的错误:
private List<String> cocNumbers;
private List<String> vatNumbers;
private List<String> ibans;
private List<String> banks;
...
List<List<String>> combinations = Utils.createCombinations(cocNumbers, vatNumbers, ibans);
Run Code Online (Sandbox Code Playgroud)
得到:
[unchecked] unchecked generic array creation for varargs parameter of type List<String>[]
方法来源:
/**
* Returns a list of all possible combinations of the entered array of lists.
*
* Example: [["A", "B"], ["0", "1", "2"]]
* Returns: [["A", "0"], ["A", "1"], ["A", "2"], ["B", "0"], ["B", "1"], ["B", "2"]]
*
* @param <T> The type parameter
* @param elements …Run Code Online (Sandbox Code Playgroud) 这对我来说是一种耻辱,但我不知道:
您应该使用clone来复制数组,因为这通常是最快的方法.
正如Josh Bloch在本博客中所述:http://www.artima.com/intv/bloch13.html
我总是用System.arraycopy(...).这两种方法都是原生的,所以可能没有深入到我无法弄清楚的库的来源,为什么会如此.
我的问题很简单:为什么它是最快的方式?
有什么区别这里
解释了不同之处,但它没有回答为什么Josh Bloch认为System.arraycopy?clone()最快的方式.
我知道在 Java 泛型中,当使用具有多个边界的类型参数时,编译器会将类型信息擦除到“最左边的边界”(即列表中的第一个类/枚举或接口)。那么为什么下面的代码编译没有问题呢?
public class Generic<T extends Object & Appendable & AutoCloseable> {
T t;
T method() throws Exception {
t.close();
char c='\u0000';
t.append(c);
return t;
}
public <T> T method2(T t) {
return t;
}
}
Run Code Online (Sandbox Code Playgroud)
类型参数 T 不应该被视为 Object 吗??(因此不允许我调用 close() 或 append())??