The Java™ Tutorials — Generics :Wildcards 通配符

The Java™ Tutorials — Generics :Wildcards 通配符

原文地址:https://docs.oracle.com/javase/tutorial/java/generics/wildcards.html

关键点

  • 通配符的适用范围: 
    • 参数类型
    • 字段类型
    • 局部变量类型
    • 返回值类型(但返回一个具体类型的值更好)

全文翻译

In generic code, the question mark (?), called the wildcard, represents an unknown type. The wildcard can be used in a variety of situations: as the type of a parameter, field, or local variable; sometimes as a return type (though it is better programming practice to be more specific). The wildcard is never used as a type argument for a generic method invocation, a generic class instance creation, or a supertype.

泛型中的问号符“?”名为“通配符”。它表示了一个位置类型。通配符可在很多场合中使用:作为一个参数、字段或者局部变量的类型;在某些时候也可作为一个返回值类型(虽然返回一个具体类型的值是更好的编程实践)。通配符从未被用于作为一个泛型方法调用、泛型类实例创建或是一个超类的类型变量。

The following sections discuss wildcards in more detail, including upper bounded wildcards, lower bounded wildcards, and wildcard capture.

下面的章节会对通配符做更深刻的讨论,包括受上下限控制的通配符和通配符匹配。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值