Home  >  Article  >  Java  >  What are the rules for using wildcards in java

What are the rules for using wildcards in java

PHPz
PHPzforward
2023-04-29 13:22:061335browse

Instructions

1. Define the in variable and use the upper limit wildcard character.

Use the extends keyword.

2. Use the super keyword and the lower limit wildcard to define the out variable.

3. If the In variable can be accessed using the method defined in the Object class, use unbounded wildcards.

4. When the code needs to access In and out variables, do not use wildcards.

Example

// 自然数
class NaturalNumber {
 
    private int i;
 
    public NaturalNumber(int i) { this.i = i; }
    // ...
}
// 偶数
class EvenNumber extends NaturalNumber {
 
    public EvenNumber(int i) { super(i); }
    // ...
}

What is Java

Java is an object-oriented programming language that can write desktop applications, Web applications, distributed systems and embedded system applications.

The above is the detailed content of What are the rules for using 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