public class GenericFoo<T> { private T elem; public GenericFoo(T elem) { super(); this.elem = elem; } public T getElem() { return elem; } @Override public String toString() { return this.elem.toString(); } }
public void useWithoutGenerics() { //Foo has a generic parameter //But we ignore it here GenericFoo foo = new GenericFoo(10); prn(foo); }
public void useWithGenerics1() {
GenericFoo<Integer> foo;
foo = new GenericFoo<>(10);
prn(foo);
}
public void useWithGenerics2() {
Rectangle rec;
rec = new Rectangle(10, 5);
GenericFoo<Rectangle> foo;
foo = new GenericFoo<>(rec);
prn(foo);
}
public GenericFoo getFoo1() { return new GenericFoo(10); }
public GenericFoo<Integer> getFoo2() {
return new GenericFoo<>(10);
}
public void printFoo1(GenericFoo foo) {
prn(foo);
}
public void printFoo2(GenericFoo<Integer> foo) {
prn(foo);
}