英文:
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<String> var = new ArrayList<String>();
While the following also runs, without my IDE giving any warnings or errors,
ArrayList<String> var1 = new ArrayList<>();
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!
专注分享java语言的经验与见解,让所有开发者获益!
评论