MeetM
MeetM

Reputation: 1430

What does <Something> in ClassName<Something > in java indicate?

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.

Upvotes: 1

Views: 357

Answers (3)

ach
ach

Reputation: 6234

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.

Upvotes: 3

Kevin
Kevin

Reputation: 3509

  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

Upvotes: 0

Related Questions