gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:15:30 27 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/57661716/

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