0

In this java code

public class Gen<T> {
    private Gen object;            //line 1
    public Gen(Gen object) {       //line 2
        this.object = object;
    }
}

I could replace line 1 with Gen<T> and line 2 with public Gen(Gen<T> object) separately, thus coming up with 4 different scenarios.

What's the difference when Gen<T> is used instead of Gen in object references?

Jeet Parekh
  • 730
  • 2
  • 7
  • 22

1 Answers1

0

You create the ability for the object to handle any data type.

For example you can create an object of type Integer:

Gen<Integer> generator = new Generator<>();

Or String:

Gen<String> generator = new Generator<>();
breen
  • 4,282
  • 5
  • 19
  • 32