1

I'm relatively new to programming in general. And I've just recently started to learn about using generics in classes and methods. However, I'm confused about the differences between the different "standard" generic parameters. On the Oracle tutorial page for generics it shows these:

E - Element (used extensively by the Java Collections Framework)
K - Key
N - Number
T - Type
V - Value
S,U,V etc. - 2nd, 3rd, 4th types

What are the differences in their uses (the one-word descriptions they give aren't super helpful)?

Does Java interpret the code differently depending on which one is used?

2
  • 2
    Nothing. And no. You can use any name you want FRED for example. Commented Apr 10, 2022 at 20:26
  • 2
    Map<K, V> is slightly more legible due to the common naming than e.g. Map<A, B>, but you're free to use any names, even longer than single characters although that can become confusing. Commented Apr 10, 2022 at 20:35

1 Answer 1

3

The names of type parameters have the same significance as do class names, methods names, or variable names: they help human readers understand the program. Nothing more, nothing less. The compiler does not care at all if your type parameter is called T or SuPeR_CALI_fragilisticEXPIALIDOCIOUS_.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.