interface Collection<E> { public void add (E x); public Iterator<E> iterator(); }
Defining such an interface means that you tell the compiler that you can create a link to this interface of any type ... But you only need to use letters to indicate a generic type.
Ideally, this is not a limitation that you should use only T, E, or V You can use any of them. But your code is more readable if you follow certain conventions ..
K - Key, V - Value .. How is it ..
So, the links for your above interface can be: -
Collection<String>, Collection<Integer>, Collection<YourCustomObject>
And whatever type you use, it will automatically affect your method return types and parameters ..
So, for Collection<String> your method will look like this: -]
public void add (String x); public Iterator<String> iterator();
source share