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 - 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…
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
-
-
-