Vote count:
-2
What is the difference between the 2 calls:
Set<Record> instances = new HashSet<Record>(); - on one hand
HashSet<Record> instances = new HashSet<Record>(); - on other hand
asked 3 mins ago
2 Answers
Vote count:
0
In the first case, you can reassign instances to an instance of any subtype of Set<Record>. In the second case, you can reassign instances only to an instance of a subtype of HashSet<Record>.
answered 46 secs ago
Vote count:
0
Set is the superclass of HashSet. Both statements store the HashSet in the variable instances.
The first statements performes an upcast from HashSet to Set. This has some advantages, such as changing HashSet to TreeSet for example.
answered 33 secs ago
Aucun commentaire:
Enregistrer un commentaire