在Java类型参数中,&lt ;?扩展E>仅意味着严格的亚型?或者E也足够了? [英] In Java type arguments, does <? extends E> mean strictly subtypes only? or would E also suffice?

查看:134
本文介绍了在Java类型参数中,&lt ;?扩展E>仅意味着严格的亚型?或者E也足够了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java类型参数中,仅仅意味着严格的子类型?或者E也足够了?

解决方案

是, super extends 分别给出了包含的上下限。

以下是 Angelika Langer的泛型常见问题解答


什么是有界通配符?



通配符的上界看起来像?类型类型类型的所有类型的族,表示类型 >被包含类型被称为上界



带有下限的通配符看起来像?超类型,代表超类型为类型,类型类型包含类型被称为下界



In Java type arguments, does mean strictly subtypes only? or would E also suffice?

解决方案

Yes, super and extends gives inclusive lower and upper bounds respectively.

Here's a quote from Angelika Langer's Generics FAQ:

What is a bounded wildcard?

A wildcard with an upper bound looks like ? extends Type and stands for the family of all types that are subtypes of Type , type Type being included. Type is called the upper bound.

A wildcard with a lower bound looks like ? super Type and stands for the family of all types that are supertypes of Type , type Type being included. Type is called the lower bound.

这篇关于在Java类型参数中,&lt ;?扩展E>仅意味着严格的亚型?或者E也足够了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆