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.
Understand generic methods and constructors - Java Tutorial
From the course: Java: Generic Classes
Understand generic methods and constructors
- [Instructor] The next part of the demo is to add generic methods to the box generic type. But before that, let's understand the concept of generic methods. So the way you define generics on the class level you can always extend that to the method level, as well. And there are two parts here that we have to talk about. Generic methods inside a generic class and generic methods outside the generic class. Let's first talk about the generic methods inside the generic class. So a method inside generic class will always have access to the type parameter that was defined on the class level. And hence, it automatically becomes a generic method relative to that type parameter. In addition to this, a method which is inside a generic class can always use more type parameters other than the ones defined on the class level. So for example, if your class has a type parameter T defined, then the method inside your generic class can…
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
-
-
-