Create a generic class
A generic type is created to adapt so that the same functionallity can be accessible for different data types.
Create a new instance of the given type
Creating a new intance of a generic type can be done/checed at compile time.
Or with limited types:
The baseClass (if none given it is Object) must have a parameter less constructor.
This can also be done at runtime through reflection
Define a 'generic' class
A generic class is a class who adapts to a later-given type so that the same functionality can be offered to different types.
In this basic example a generic class is created. It has a sub who uses the generic type T. While programming this class, we don't know the type of T. In this case T has all the characteristics of Object.
Instance of a Generic Class
By creating an instance of the same class with a different type given, the interface of the class changes depending on the given type.
Limit the possible types given
The possible types passed to a new instance of SomeClass must inherit SomeBaseClass. This can also be an interface. The characteristics of SomeBaseClass are accessible within this class definition.
Use a generic class
In this example there are 2 instances created of the SomeClass Class. Depending on the type given the 2 instances have a different interface:
The most famous generic class is List(of )