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.

Implement a generic method as a utility

Implement a generic method as a utility - Java Tutorial

From the course: Java: Generic Classes

Implement a generic method as a utility

- In our previous video, we added methods inside the generic class. Let's also do one more bit of this demo where we add a method outside the generic class box. So I have the steps to mention on this slide let's execute them, one by one. Let's first add a utility class called BoxUtils. So let's head back to the IDE and on the same package, I will create a class. Let's call it BoxUtils. The next step will be add a generic method getCountOfItems. So the method that I'm going to add in the utility class is to get a count of items from any box that we want to measure the count on. So let's go back to the IDE and here let's add a method, public and they should return int. Let's name the method getCountOfItems and they should have some parameter and then the definition. So now let's try to understand this. We are trying to get the count of items from the box. So this method should be able to access the type parameter of the…

Contents