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
  • 740
  • 2
  • 8
  • 25

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<>();
Lawrence Aiello
  • 4,560
  • 5
  • 21
  • 35