You have bumped into "generics". They are explained very nicely in this guide.
In short, they allow you to specify what type that a storage-class, such as a List
or Set
contains. If you write Set<String>
, you have stated that this set must only contain String
s, and will get a compilation error if you try to put something else in there:
Set<String> stringSet = new HashSet<String>();
stringSet.add("hello"); //ok.
stringSet.add(3);
^^^^^^^^^^^ //does not compile
Furthermore, another useful example of what generics can do is that they allow you to more closely specify an abstract class:
public abstract class AbstClass<T extends Variable> {
In this way, the extending classes does not have to extend Variable
, but they need to extend a class that extends Variable
.
Accordingly, a method that handles an AbstClass
can be defined like this:
public void doThing(AbstClass<?> abstExtension) {
where ?
is a wildcard that means "all classes that extend AbstClass
with some Variable
".