1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
MeetM
  • 1,410
  • 17
  • 25

3 Answers3

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
  1. Car is your "Car-Object class" you are passing in.
  2. <> symbols are used for specifying type of Object you want for your Key class
Kevin
  • 3,509
  • 4
  • 31
  • 45