I was reading some tutorial where I came across terms like
Key<Car> rootKey = new Key<Car>(Car.class, 959);
What does <Car>
mean in this code? Why are these "<>" symbols used here? Please help.
Asked
Active
Viewed 345 times
1
-
1Welcome to the world of generics. – Tyler Treat Apr 03 '12 at 21:35
-
1http://docs.oracle.com/javase/tutorial/java/generics/generics.html – Adam Apr 03 '12 at 21:35
-
possible duplicate of [What do < and > mean such as implements Comparable
?](http://stackoverflow.com/questions/450520/what-do-and-mean-such-as-implements-comparablebiginteger) – Tomalak Apr 03 '12 at 21:35
3 Answers
3
The in your snippet represents a generic type specifier. You can instantiate class Key with a type other than Car and its methods will be type-safe for that variable at compile time.
For example, the following statement is type-safe, just as your example is:
Key<String> rootKey = new Key<String>(String.class, "someString");
See http://docs.oracle.com/javase/tutorial/java/generics/gentypes.html for more information.

ach
- 6,164
- 1
- 25
- 28
1
Java Generic Types: http://docs.oracle.com/javase/tutorial/java/generics/gentypes.html

Marcos
- 4,643
- 7
- 33
- 60
0
- Car is your "Car-Object class" you are passing in.
- <> symbols are used for specifying type of Object you want for your Key class

Kevin
- 3,509
- 4
- 31
- 45