qazwsx
qazwsx

Reputation: 26938

In Java, what's the difference between HashSet<Integer> = new HashSet(2) and HashSet<Integer> = new HashSet<Integer>(2)?

Is there any difference between initializing using

HashSet<Integer> s = new HashSet(2) 

and

HashSet<Integer> s = new HashSet<Integer>(2)

?

Upvotes: 0

Views: 83

Answers (2)

Hot Licks
Hot Licks

Reputation: 47739

Interestingly, compiling with javac 1.7.0_07:

Compiles with unchecked warning --

HashSet<Integer> s0 = new HashSet(2);

Compiles with no messages --

HashSet<Integer> s1 = new HashSet<>(2);
HashSet<Integer> s2 = new HashSet<Integer>(2);

Upvotes: 1

user207421
user207421

Reputation: 311008

The only difference is that the first one will give you a compiler warning about the raw type 'HashSet'.

Upvotes: 2

Related Questions