What's the difference between these two java variable declarations?

后端 未结 5 1725
小蘑菇
小蘑菇 2020-12-21 17:10
public class SomeClass {
    private HashSet contents = new HashSet();
    private Set contents2 = new HashSet&         


        
5条回答
  •  被撕碎了的回忆
    2020-12-21 17:34

    Set is a collection interface that HashSet implements.

    The second option is usually the ideal choice as it's more generic.

提交回复
热议问题