Advance-Java Generic in Java #28

Publié le: 23 avril 2022
sur la chaîne: 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.


Sur cette page du site, vous pouvez voir la vidéo en ligne Advance-Java Generic in Java #28 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur King of Techniques 23 avril 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 79 fois et il a aimé 2 téléspectateurs. Bon visionnage!