这两个ArrayList构造函数之间有什么区别?

huangapple 未分类评论54阅读模式
英文:

What's the difference between these two ArrayList constructors?

问题

我一直在为课程编写基本的Java程序,但我喜欢展望未来,独立于课程学习新的东西。

当我在研究Java中的ArrayList时,我注意到我可以进行以下操作,而且两者似乎都能正常工作,

ArrayList<String> var = new ArrayList<String>();

而以下操作也能运行,而且我的集成开发环境没有显示任何警告或错误,

ArrayList<String> var1 = new ArrayList<>();

因此,我对为什么存在第二组尖括号感到困惑,因为它在代码中似乎没有任何区别。

非常感谢您的所有帮助!

英文:

I've been working on basic Java programs for classes, however, I like to look ahead and learn new things independent of the class.

While I was looking at ArrayLists in Java, I noticed that I could do the following, and both seem to work,

ArrayList&lt;String&gt; var = new ArrayList&lt;String&gt;();

While the following also runs, without my IDE giving any warnings or errors,

ArrayList&lt;String&gt; var1 = new ArrayList&lt;&gt;();

Thus I am confused as to why the second set of chevrons exist, it doesn't seem to make a difference in the code.

Any and all help is appreciated!

huangapple
  • 本文由 发表于 2020年3月15日 12:45:16
  • 转载请务必保留本文链接:https://java.coder-hub.com/60689818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定