课程: Java: Advanced Concepts for High-Performance Development
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Generic methods in Java - Java教程
课程: Java: Advanced Concepts for High-Performance Development
Generic methods in Java
- [Instructor] Generic methods are a special type of method that let us pass in different types of objects as arguments. This is best shown with an example. So in this example, I have a class called GenericMethods and inside the class I have a main method and inside the main method I have two arrays. The first one is an array of strings and that contains the words apple, banana, and pear. And then the second one is an array of integers and that contains the numbers 1, 5, and 7. So let's say I want to write a method that lets you pass in either of these arrays and converts that array to a list. I want my method to work with arrays containing any types of objects. So I could write two separate methods here. One for converting arrays of strings to lists of strings and another one for converting a array of integers to lists of integers. But using generics, I only need to write one method. So the first thing I need to do is…
内容
-
-
-
-
Introduction to generics in Java4 分钟 15 秒
-
(已锁定)
Generic methods in Java3 分钟 24 秒
-
(已锁定)
Bounded generics in Java1 分钟 43 秒
-
(已锁定)
The Liskov substitution principle in Java4 分钟 28 秒
-
(已锁定)
Using wildcards in generic programming2 分钟 45 秒
-
(已锁定)
Challenge: Using generics2 分钟 17 秒
-
(已锁定)
Solution: Using generics1 分钟 41 秒
-
-
-
-
-
-
-