通用接口将自己作为参数。递归泛型? [英] Generic Interface takes self as Parameter. Recursive Generic?

查看:129
本文介绍了通用接口将自己作为参数。递归泛型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:我没有太多的Java Generics经验,但我的同事和我花了一整小时试图破译这样构造的接口:

Disclaimer: I don't have a whole ton of experience with Java Generics, but my colleagues and I just spent a solid hour trying to decipher an interface that was structured like this:

interface HasAttributes<A extends HasAttributes<A, B>, 
                        B extends HasAttributesType<B>> extends Identification<B> {

当一个接口泛型接受一个自己的类型参数时,究竟意味着什么?这是干什么的?

What exactly does it mean when an interface generic takes a type parameter that is itself? What does this do?

推荐答案

public abstract class Enum<E extends Enum<E>>
    implements Comparable<E>, Serializable

这个关于枚举的堆栈溢出问题应该为您介绍这种特殊的泛型使用方法,以及更多地回答这个问题优雅地比我能。

There are some enlightening answers in this Stack Overflow question about Enum that should shed some light on this particular use of generics for you, as well as answer this more elegantly than I could.

这篇关于通用接口将自己作为参数。递归泛型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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