Home > Java > javaTutorial > How to use lower bound wildcard in java

How to use lower bound wildcard in java

王林
Release: 2023-04-19 20:58:05
forward
1382 people have browsed it

Explanation

1. The lower limit wildcard limits unknown types to specific types or supertypes.

2. The lower bound wildcard uses the wildcard character ('?').

means that it is followed by the super keyword, and then its lower limit .

3. The class instantiated under the wildcard must be the current class or the superclass of the current class.

When storing data, the data type can only be the current class or the superclass of the current class.

Examples

public static void addNumbers(List<? super Integer> list) {
    for (int i = 1; i <= 10; i++) {
        list.add(i);
    }
}
Copy after login

What collection classes are there in Java

Collections in Java are mainly divided into four categories:

1, List List: ordered, repeatable;

2, Queue queue: ordered, repeatable;

3, Set collection: non-repeatable;

4, Map mapping: unordered, unique keys, non-unique values.

The above is the detailed content of How to use lower 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