Home > Java > javaTutorial > body text

How to use upper bound wildcard in java

WBOY
Release: 2023-05-31 11:10:07
forward
1433 people have browsed it

Explanation

1. The upper limit wildcard can be used to relax restrictions on variables.

For example, suppose you want to write a method that handles List, List and List, then you can achieve this by using upper bound wildcards.

2. The class instantiated by the upper bound wildcard must be the current class or a subclass of the current class.

3. If you want to declare an upper bound wildcard, please use a wildcard value.

Then comes the extends keyword, and finally its upper bound. Please note that in this context, extends is generally used to mean either extends (such as a class) or implements (such as an interface).

Example

public static void process(List<? extends Foo> list) {
    for (Foo elem : list) {
        // ...
    }
}
Copy after login

What can Java be used for?

Java is mainly used in:

1.web development;

2. Android development;

3. Client development;

4. Web development;

5. Enterprise application development;

6. Java big data development;

7. Game development, etc.

The above is the detailed content of How to use upper bound wildcard in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template