Home  >  Article  >  Java  >  How to use unbounded wildcards in Java?

How to use unbounded wildcards in Java?

WBOY
WBOYforward
2023-05-07 22:43:061518browse

Explanation

#1. If you are writing a method that can be implemented using the functions provided in the Object class. Unbounded wildcard types are specified using wildcard characters.

For example, list < ? > . This is called a list of unknown type.

2. When the code uses methods in generics that do not rely on type parameters.

For example, List.size or List.clear. In fact, many methods using Class do not depend on T, so Class is so often used because most of the methods in Class do not depend on T .).

Example

public static void printList(List<Object> list) {
    for (Object elem : list)
        System.out.println(elem + " ");
    System.out.println();
}

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type , a data type used to represent integers.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of How to use unbounded wildcards in Java?. 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