From the course: Java: Generic Classes
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Create a generic class demo - Java Tutorial
From the course: Java: Generic Classes
Create a generic class demo
- [Instructor] In our previous video, we have already seen the overview of everything that we need to do in order to build our generic class box. We will split this demo into two parts for the sake of simplicity. In the first part, we'll code everything on the box class, and we'll also code our type arguments, which is Book and Fruit. We'll test this out. In the subsequent videos, we will add methods, and then test everything together as a whole unit. Now, I have steps mentioned on the slide in order to get started for building the generic class box. So let's execute those steps one by one. The first step is to create a class box and define a type parameter T for it. Let's head back to the IDE. And on this package, let's create a class called box. And this time, it is going to have a type parameter. So you have to enclose that type parameter in a pair of angle brackets like that, done. The second step is to declare a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Generic classes/interface use case3m 48s
-
(Locked)
Create a generic class demo8m 17s
-
(Locked)
Understand generic methods and constructors8m 36s
-
(Locked)
Implement a generic method as a utility4m 38s
-
(Locked)
Using bounded types14m 6s
-
(Locked)
Challenge: Write code using generic classes/bounded types1m 38s
-
(Locked)
Solution: Write code using generic classes/bounded types8m 10s
-
-
-