1. The upper bound wildcard character extends T>
The upper bound wildcard character allows read operations. For example
Fruit fruit=p.get(); Object object=p.get();
2, the lower bound wildcard character super T>
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 super T> 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.
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!