• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Why we use the alphabet T & R for Interface Function<T,R>?

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Per https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html, it has the following explanation.

Interface Function<T,R>

Type Parameters:
T - the type of the input to the function
R - the type of the result of the function

Why are we using T & R instead of X & Y? Is there any special meaning to T & R? I always forget which one is input and which one is output.
 
Sheriff
Posts: 8526
615
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is down to convention. You can see type parameters naming convention here (<- link).

As you mentioned yourself T - type of input, R - type of Result. Shouldn't be that complicated to remember, maybe need some time to get used to it. Read that whole tutorial I gave you.
 
Saloon Keeper
Posts: 14499
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Commonly used generic type parameter names:

T - primary type
U - secondary type
R - result type
E - element type
K - key type
V - value type

This is just convention. They could have used X and Y, but I suppose T invokes a greater sense that your dealing with a type parameter and not a regular variable.

[edit]

I see Liutauras' link already mentions these.
 
I'm full of tinier men! And a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic