I mean those brackets < >
thanks a lot, world class experts on Stack Overflow!!
I mean those brackets < >
thanks a lot, world class experts on Stack Overflow!!
They're used to denote generic types and methods.
So for instance, the following:
class Foo<T> {
void set(T t) {
this.t = t;
}
private T t;
}
is a generic class paramterised on T
. It's used to enforce type-safety, thus:
class X {}
class Y {}
Foo<X> foo_x = new Foo<X>();
Foo<Y> foo_y = new Foo<Y>();
foo_x.set(new X()); // ok
foo_y.set(new Y()); // ok
foo_x.set(new Y()); // compiler error!
In addition to generics and numeric comparisons, there's also bitwise operations. Can't remember ever doing that in java though.