Advance-Java Generic in Java #28

Published: 23 April 2022
on channel: King of Techniques
79
2

#java #javacourse #Generics #genericsin java

‪@kingoftechniques6864‬

Generics in Java are the advanced feature that helps to achieve code reusability and type safety. The code reusability functionality in java is managed by defining generic classes, interfaces, constructors, methods. Generic uses the data type declaration for a type safety feature that helps to eliminate the run time error.

The idea is to allow type (Integer, String, … etc, and user-defined types) to be a parameter to methods, classes, and interfaces. Using Generics, it is possible to create classes that work with different data types. An entity such as class, interface, or method that operates on a parameterized type is called a generic entity.

We can call the generics method by placing the actual type String and Integer inside the bracket before the method name. Note: We can call the generics method without including the type parameter. For example, In this case, the compiler can match the type parameter based on the value passed to the method.
Here, we are using the T type parameter to create the generic class of specific type. Let's see a simple example to create and use the generic class. The T type indicates that it can refer to any type (like String, Integer, and Employee). The type you specify for the class will be used to store and retrieve the data.


On this page of the site you can watch the video online Advance-Java Generic in Java #28 with a duration of hours minute second in good quality, which was uploaded by the user King of Techniques 23 April 2022, share the link with friends and acquaintances, this video has already been watched 79 times on youtube and it was liked by 2 viewers. Enjoy your viewing!