![]() |
VOOZH | about |
Generic means parameterized types introduced in java5. These help in creating classes, interfaces, methods, etc. A class or method which works on parameterized type known as "generic class " or "generic method". Generics is a combination of language properties of the definition and use of Generic types and methods. Collections were used before Generics which holds any type of objects i.e. non-generic. Using Generics, it has become possible to create a single class, interface, or method that automatically works with all types of data(Integer, String, Float, etc). It has expanded the ability to reuse the code safely and easily. Generics also provide type safety (ensuring that an operation is being performed on the right type of data before executing that operation).
Hierarchical classifications are allowed by Inheritance. Superclass is a class that is inherited. The subclass is a class that does inherit. It inherits all members defined by super-class and adds its own, unique elements. These uses extends as a keyword to do so.
Sometimes generic class acts like super-class or subclass. In Generic Hierarchy, All sub-classes move up any of the parameter types that are essential by super-class of generic in the hierarchy. This is the same as constructor parameters being moved up in a hierarchy.
Example 1: Generic super-class
value : 100
Note: A subclass can freely add its own type parameters, if necessary.
Example 2: Non-generic sub-class of generic sub-class
Hello 2021