简体   繁体   English

Java泛型:做什么 <? extends Interface <?> &gt;是什么意思?

[英]Java Generics: what does <? extends Interface <?>> mean?

Further to a previous post I'm hope someone can help clarify/confirm my understanding of the following java generics statements, and offer some input as to what the final one means: 在上一篇文章之后,我希望有人可以帮助澄清/确认我对以下java泛型语句的理解,并提供一些有关最终含义的信息:

If: 如果:

Class<abc> className = x

means to assign x of type abc to Class variable className 表示将abc类型的x分配给Class变量className

And: 和:

Class<? extends IAbc> className = x

means to assigns x which implements interface IAbc to Class variable className 将实现接口IAbc x分配给Class变量className

What does: 是什么

Class<? extends IAbc<?>> className = x

mean? 意思?

That just means that IAbc is itself a generic type IAbc<T> , you're asking for a Class object representing some implementation of some parameterization of IAbc but you don't know (or care?) which. 那只是意味着IAbc本身就是泛型类型IAbc<T> ,您要的是一个Class对象,该对象表示IAbc的某些参数化的某种实现,但您不知道(或不在乎)哪个。

More interesting would be something like 更有趣的是

Class<? extends IAbc<? extends Number>>

which would accept any class that implements IAbc<Number> , IAbc<Integer> , IAbc<Double> , etc. 它将接受实现IAbc<Number>IAbc<Integer>IAbc<Double>等的任何类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM