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

What are the rules for using wildcards in java

PHPz
Release: 2023-04-29 13:22:06
forward
1376 people have browsed it

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); }
    // ...
}
Copy after login

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!

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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template