gpt4 book ai didi

java - 实例化用户定义类型集合的约定是什么?

转载 作者:搜寻专家 更新时间:2023-10-30 19:40:21 25 4
gpt4 key购买 nike

我有一个名为 MatchingLine 的类

    public class MatchingLine implements Comparable
{
private String matchingLine;
private int numberOfMatches;

// constructor...
// getters and setters...
// interface method implementation...
}

我在 ArrayList 中使用这个类如下 -

    ArrayList<MatchingLine> matchingLines = new ArrayList<MatchingLine>();

但是,Netbeans IDE 会在该语句旁边添加一条注释,并指出:

   redundant type arguments in new expression (use diamond operator instead)

它建议我使用 -

    ArrayList<MatchingLine> matchingLines = new ArrayList<>();

我一直以为前一种风格是约定俗成的?后一种风格是惯例吗?

最佳答案

ArrayList<MatchingLine> matchingLines = new ArrayList<>();

这是 Java 7 中的一项新功能,称为 diamond operator .

关于java - 实例化用户定义类型集合的约定是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10075473/

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