What's the difference between these two java variable declarations?
public class SomeClass { private HashSet<SomeObject> contents = new HashSet<SomeObject>(); private Set<SomeObject> contents2 = new HashSet<SomeObject>(); } What's the difference? In the end they are both a HashSet isn't it? The second one looks just wrong to me, but I have seen it frequently used, accepted and working. Alan Geleynse Set is an interface, and HashSet is a class that implements the Set interface. Declaring the variable as type HashSet means that no other implementation of Set may be used. You may want this if you need specific functionality of HashSet . If you do not need any