Consider this Generics Code:
interface Collection<E> {
public void add (E x);
public Iterator<E> iterator();
}
And this one:
public class MyClass<V> {
V v;
setSomeValue(V val) {
v=val;
}
V getSomeValue() {
return v;
}
}
My Question:
Do those letters in angular brackets:
<V> and <E>
have specific meaning.
Can i use any English Alphabet. i.e can they be
<A> or <Q>?
They do have to be valid Java identifiers (not necessarily just single letters as pointed out in the comment,) technically you can use any identifier that you like and your code will compile and run fine (if there are no other errors of course!)
It’s good to stick to convention though – this tends to be single capital letters. Some common ones are
E,T,KandV, standing for element, type, key and value respectively – your use case may well fit into one of those categories, in which case I’d use those letters. In the case of the above example, theCollectionclass usesEbecause it contains elements.