The purpose of the Java Collections API is to provide a well defined hierarchy of interfaces in order to hide implementation details. Implementing classes must be used to instantiate new collections, but the result of an instantiation should ideally be stored in a variable whose type is a Java Collection interface. This rule raises an issue when an implementation class: * is returned from a ``++public++`` method. * is accepted as an argument to a ``++public++`` method. * is exposed as a ``++public++`` member. == Noncompliant Code Example ---- public class Employees { private HashSet employees = new HashSet(); // Noncompliant - "employees" should have type "Set" rather than "HashSet" public HashSet getEmployees() { // Noncompliant return employees; } } ---- == Compliant Solution ---- public class Employees { private Set employees = new HashSet(); // Compliant public Set getEmployees() { // Compliant return employees; } } ---- ifdef::env-github,rspecator-view[] ''' == Implementation Specification (visible only on this page) include::message.adoc[] ''' == Comments And Links (visible only on this page) include::comments-and-links.adoc[] endif::env-github,rspecator-view[]