How to use wildcards in java method parameters
This article mainly introduces "how to use wildcards in java method parameters". In daily operation, I believe many people have doubts about how to use wildcards in java method parameters. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use wildcards in java method parameters". Next, please follow the editor to study!
Description
1. Wildcard characters? Super Frui defines the lower bound of generics as Fruit.
2. Generic objects and Generic objects can be passed to print2 as parameters. However, Generic objects cannot be passed in as parameters because Apple is a subclass of Fruit and exceeds the lower bound specified by generics.
Example
Generic fruitGeneric2 = new Generic (); print2 (fruitGeneric2); Generic foodGeneric2 = new Generic (); print2 (foodGeneric2); / / misuse / / Generic appleGeneric2 = new Generic (); / / print2 (appleGeneric2); at this point, the study of "how to use wildcards in java method parameters" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!