Home  >  Article  >  Java  >  What are the wildcard characters in Java generics

What are the wildcard characters in Java generics

WBOY
WBOYforward
2023-05-03 08:13:142120browse

1. The upper bound wildcard character

The upper bound wildcard character allows read operations. For example

Fruit fruit=p.get();
Object object=p.get();

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete