A Guide to Understand Java Generics with Examples
- Description
- Curriculum
- FAQ
- Reviews
Java Generics
Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively. Generics also provide compile-time type safety that allows programmers to catch invalid types at compile time. This reference will take you through simple and practical methods using Java Generics.
The Java Generics programming is introduced in J2SE 5 to deal with type-safe objects. It makes the code stable by detecting the bugs at compile time.
Before generics, we can store any type of objects in the collection, i.e., non-generic. Now generics force the java programmer to store a specific type of objects.
It would be nice if we could write a single sort method that could sort the elements in an Integer array, a String array, or an array of any type that supports ordering.
Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively.
Generics also provide compile-time type safety that allows programmers to catch invalid types at compile time.
Using Java Generic concept, we might write a generic method for sorting an array of objects, then invoke the generic method with Integer arrays, Double arrays, String arrays and so on, to sort the array elements.
-
2Java Generics OverviewVideo lesson
-
3Example to Understand the power of genericsVideo lesson
-
4Arrays vs Collection IntroductionVideo lesson
-
5Arrays vs Collection vs Generics ExampleVideo lesson
-
6Why we need genericsVideo lesson
-
7Generic Class Syntax IntroductionVideo lesson
-
8Generic Class Example Part1Video lesson
-
9Generic Class Example Part2Video lesson
-
10Generics Naming ConventionsVideo lesson
-
11Generic Example With K Type and V TypeVideo lesson
-
12Type Inference in Java with GenericsVideo lesson
-
13Generic Method IntroductionVideo lesson
-
14Generic Method With Void ExampleVideo lesson
-
15Generic Method With Return ExampleVideo lesson
-
16Raw Type Generic ExampleVideo lesson
-
17Upper Bound Generic IntroductionVideo lesson
-
18Upper Bound Generic ExampleVideo lesson
-
19Multiple UpperBound ExampleVideo lesson
-
20Upper Bound Wildcard IntroductionVideo lesson
-
21Upper Bound Wildcard Example1Video lesson
-
22Upper Bound Wildcard Example2Video lesson
-
23Upper Bound RestrictionVideo lesson
-
24Lower Bound Example IntroductionVideo lesson
-
25Lower Bound ExampleVideo lesson
-
26UnBounded Wildcard ExampleVideo lesson

External Links May Contain Affiliate Links read more