0

I am manipulating some code and unfortunately I cannot understand this part of it:

public class InMemoryTreeStateManager<T> implements TreeStateManager<T>

What is the meaning of <T>. in this code?

Ahmad
  • 69,608
  • 17
  • 111
  • 137
Sal-laS
  • 11,016
  • 25
  • 99
  • 169

4 Answers4

3

This is a generic. It means T can be any class, and you need to specify what type when you declare a variable of that type. Similar to C++ templates, if you're familiar with that.

Ahmad
  • 69,608
  • 17
  • 111
  • 137
Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
3

It is generics, it takes some time getting familiar with. you can read more about it here: http://en.wikipedia.org/wiki/Generics_in_Java

Vegard
  • 1,802
  • 2
  • 21
  • 34
1

<T> is a generic type. Basically TreeStateManager works with any class that you pass to it, and you can tell it what type of class that is by putting the class name into the braces.

Maloric
  • 5,525
  • 3
  • 31
  • 46
0

That's stating InMemoryTreeStateManager is a generic class.

If you would want to instantiate this object (without warnings of raw types) you'd have to give the class a type.

i.e.

InMemoryTreeStateManager<String> manager = new InMemoryTreeStateManager<String>();
dardo
  • 4,870
  • 4
  • 35
  • 52