gpt4 book ai didi

java - <> 对 java 泛型意味着什么?

转载 作者:IT老高 更新时间:2023-10-28 20:55:43 26 4
gpt4 key购买 nike

我有一点代码:

class MyClass<RCM> 
private List<RCM> allPreExistingConfigsForCodes() {
if(this.allCodesForThisType.size() == 0)
return new ArrayList<RCM>(0);

IntelliJ 告诉我应该替换 new ArrayList<RCM>new ArrayList<>那是什么意思?

最佳答案

来自 Java Tutorials generics lesson :

In Java SE 7 and later, you can replace the type arguments required to invoke the constructor of a generic class with an empty set of type arguments (<>) as long as the compiler can determine, or infer, the type arguments from the context. This pair of angle brackets, <>, is informally called the diamond. For example, you can create an instance of Box<Integer> with the following statement:

Box<Integer> integerBox = new Box<>();

关于java - <> 对 java 泛型意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8660202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com