-5

I mean those brackets < >

thanks a lot, world class experts on Stack Overflow!!

4 Answers4

6

Let's not forget numeric comparisons!

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
4

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!
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
2

In addition to generics and numeric comparisons, there's also bitwise operations. Can't remember ever doing that in java though.

flesk
  • 7,439
  • 4
  • 24
  • 33
0

Yeah. Generics.

List<String> mylist = new ArrayList<String>();
John B
  • 32,493
  • 6
  • 77
  • 98