Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - What's <> used and what's its name?

Tags:

java

generics

I'm working through some sample code and then this appeared:

public abstract class RandomPool<T> extends Pool {
     //Class...
}

What's <> used for? And why is just T inside these? This seems to be very random for me. However, how can I use it in a longer perspective of making programs?

Thanks and tell me if I need to add more details!

like image 369
Curtain Avatar asked Jan 10 '11 17:01

Curtain


2 Answers

See Java Generics

T stands for "Type"

like image 200
dom farr Avatar answered Oct 14 '22 09:10

dom farr


Generics

T is a placeholder for whatever type is used at runtime. For example you could use:

RandomPool<String> pool;

T would refer to String in that case.

Read the Java Generics Tutorial

like image 45
Adam Avatar answered Oct 14 '22 08:10

Adam