So I have to use a TreeSet
in my code.
As TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable
and interface NavigableSet<E> extends SortedSet<E> which extends Set<E>
I can use any of these three declaration:
NavigableSet<String> myTreeSet= new TreeSet<>();
SortedSet<String> myTreeSet= new TreeSet<>();
Set<String> myTreeSet= new TreeSet<>();
I know I will be having access to only those method which are exposed by the Interface I am using in the declaration. Is there any other reason to consider for selecting a particular declaration for a TreeSet
?