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

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…

Contents