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

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…

Contents