[英]In Java, what's the difference between HashSet<Integer> = new HashSet(2) and HashSet<Integer> = new HashSet<Integer>(2)?
初始化使用之间有什么区别
HashSet<Integer> s = new HashSet(2)
和
HashSet<Integer> s = new HashSet<Integer>(2)
?
唯一的不同是,第一个将向您提供有关原始类型'HashSet'的编译器警告。
有趣的是,使用javac 1.7.0_07进行编译:
编译时显示未经检查的警告-
HashSet<Integer> s0 = new HashSet(2);
编译无消息-
HashSet<Integer> s1 = new HashSet<>(2);
HashSet<Integer> s2 = new HashSet<Integer>(2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.