Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
Marshal
Posts: 8198
585
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: 13483
304
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic