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?
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?
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.
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
<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.
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>();