0

In java profiler command output, I've been seeing these notations in angular braces like

java.util.Queue<E>
java.util.TreeMap<K, V>

Correct me if I'm wrong; working through some exercises, I've been able to relate E-Entity, K,V - Key-Value pair. I've seen others like java.lang.Iterable<T>, for which I couldn't figure out what T is for.

Can someone help me in telling what these notations are called and how many such exist in Java SE?

Sai Kiran
  • 61
  • 7

2 Answers2

1

They’re called generics. They allow a method/class/interface etc. to operate on multiple types of Object (e.g. Integer, String) without compromising type checking.

See:

Matt
  • 2,063
  • 1
  • 14
  • 35
1

You are talking about a aspect of the java programming language called generics You can read more about them here

The letters used don't actually matter. As you said, in the java.util.TreeMap<K, V> interface, the letters 'K' and 'V' were used, probably because they are the first letters in the words "key" and "value", but any other letters could have been used. Java does not care what letters you use when defining a generic class or interface, that part is all up to you.

HomeworkHopper
  • 300
  • 1
  • 12