What does in ClassName in java indicate?

Go To StackoverFlow.com

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.

2012-04-03 21:34
by MeetM
Welcome to the world of generics - Tyler Treat 2012-04-03 21:35
http://docs.oracle.com/javase/tutorial/java/generics/generics.htm - Adam 2012-04-03 21:35
possible duplicate of What do < and > mean such as implements Comparable<BigInteger>?Tomalak 2012-04-03 21:35


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.

2012-04-03 21:40
by ach


1



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
2012-04-03 21:37
by Kevin