Home > Java > javaTutorial > body text

What are the wildcard characters in Java generics

WBOY
Release: 2023-05-03 08:13:14
forward
2140 people have browsed it

1. The upper bound wildcard character

The upper bound wildcard character allows read operations. For example

Fruit fruit=p.get();
Object object=p.get();
Copy after login

2, the lower bound wildcard character

The lower bound wildcard character means that only data of T and its base class type can be stored in the container. .

3. Wildcard

Unbounded wildcard means that any object can be used, so using it is similar to using native types. But it works. Native types can hold any type, while unbounded wildcard-modified containers hold a specific type.

PECS principle

The upper bound

Lower bound does not affect inward storage, but outward retrieval can only be placed in the Object object, which is suitable for scenarios where data is often inserted into it.

What collection classes are there in Java?

Collections in Java are mainly divided into four categories:

1. List: ordered, repeatable;

2. Queue: ordered and repeatable;

3. Set: non-repeatable;

4. Map: unordered, with unique keys and non-unique values.

The above is the detailed content of What are the wildcard characters in Java generics. 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